I'm looking for the standard practice in specifying that a certain HTML element, like a "Create user" button should only be displayed when the user is logged-in and belongs to the role "Administrator."
For example, using Spring MVC in Java, the Spring Security tag library has a control that does just that:
<sec:authorize access="hasRole('ROLE_PRESIDENT')">
<input type="button" value="Launch nuclear weapons"/>
</sec:authorize>
Whatever appears between the tags will only display when the user belongs to the role specified.
Does ASP.NET MVC have such feature?
For Razor view engine:
@if (User.IsInRole("ROLE_PRESIDENT")) {
<input type="button" value="launch nuclear weapons" />
}
For Webforms view engine:
<% if (User.IsInRole("ROLE_PRESIDENT")) { %>
<input type="button" value="launch nuclear weapons" />
<% } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With