Naming of the <dot:IfAuthorized> control
See original GitHub issueThe IfAuthorized
control name, which is now in the framework, doesn’t make sense. If the user is not authorized, he won’t even be allowed to open the page. The correct name would be IfAuthenticated
, but I don’t like the If in the control name.
In ASP.NET Web Forms, there was the LoginView
control which did exactly the same thing - it had AnonymousTemplate
and LoggedInTemplate
properties, and it also allowed to display different content for each role. In DotVVM, we should have something similar, maybe we could preserve the naming.
<dot:LoginView>
<AnonymousTemplate>
This will be displayed to non-authenticated users.
</AnonymousTemplate>
<LoggedInTemplate>
This will be displayed to authenticated users.
</LoggedInTemplate>
</dot:LoginView>
The role functionality can be easily implemented by a separate control RoleView
:
<dot:RoleView Roles="admin,moderator">
This will be displayed only to the users which have the role
</dot:RoleView>
Also, we could have a similar control for specific app environments:
<dot:EnvironmentView Name="debug">
This will be displayed only in the debug environment.
</dot:EnvironmentView>
Or shall the control names be IfLoggedIn
(or IfAuthenticated
), IfInRole
(or IfRoleMember
), IfEnvironment
with templates called TrueTemplate
and FalseTemplate
?
Do you have another ideas?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
OK, to sum this up, we just need:
I don’t want while, goto or fors in the markup, the “if” is just enough. I just wanted the naming to be consistent, that’s why I’ve suggested
<dot:IfUser>
,<dot:IfEnvironment>
and because these classes would probably inherit from some BaseIfControl, why not just add<dot:If>
and evaluate the condition on server? This approach would solve all points I have mentioned above, and the naming would be consistent. Also, it would be extensible and we may later need something like<dot:IfConfiguration>
etc.If we name the control
<AuthenticatedView>
, we have to also think about the names for the other situations - it needs to be consistent because the controls are similar.P.S. If you want to test the claims and the identity would be GenericPrincipal, I don’t think that we should throw an exception. I’d prefer the condition to be evaluated to
false
because the generic identity has no claims.<dot:If Condition="{value: expression}">
this piece of code looks like MSBuild 😄I prefer
AuthenticatedView
suggested by @Mylan719AuthenticatedTemplate
andAnonymousTemplate
for this component seem to me be OK.What about to add something like
<div RenderSettings.Render="{value: ServerEvaluatedCondition }">
or perhaps<div CanRender="{value: ServerEvaluatedCondition }">
? When the condition is false the element is not simply rendered.I tried to understand why you want the dot:ifsomehting controls. It seem to me like dot:goto.
About the claims. How these components will react when CurrentPrincipal is GenericPrincipal instance?