Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can subtype <code>AuthorizeAttribute</code> to look at Users <em>and</em> Roles. off the top of my head (untested):</p> <pre><code>using System; using System.Linq; using System.Security.Principal; using System.Web; using System.Web.Mvc; public class MyAuthorizeAttribute : AuthorizeAttribute { // This method must be thread-safe since it is called by the thread-safe OnCacheAuthorization() method. protected override bool AuthorizeCore(HttpContextBase httpContext) { base.AuthorizeCore(httpContext); if ((!string.IsNullOrEmpty(Users) &amp;&amp; (_usersSplit.Length == 0)) || (!string.IsNullOrEmpty(Roles) &amp;&amp; (_rolesSplit.Length == 0))) { // wish base._usersSplit were protected instead of private... InitializeSplits(); } IPrincipal user = httpContext.User; if (!user.Identity.IsAuthenticated) { return false; } var userRequired = _usersSplit.Length &gt; 0; var userValid = userRequired &amp;&amp; _usersSplit.Contains(user.Identity.Name, StringComparer.OrdinalIgnoreCase); var roleRequired = _rolesSplit.Length &gt; 0; var roleValid = (roleRequired) &amp;&amp; _rolesSplit.Any(user.IsInRole); var userOrRoleRequired = userRequired || roleRequired; return (!userOrRoleRequired) || userValid || roleValid; } private string[] _rolesSplit = new string[0]; private string[] _usersSplit = new string[0]; private void InitializeSplits() { lock(this) { if ((_rolesSplit.Length == 0) || (_usersSplit.Length == 0)) { _rolesSplit = Roles.Split(','); _usersSplit = Users.Split(','); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload