Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With MVC it is simple to bypass the Membership and Role provider framework altogether. Sometimes it is easier to do this than to implement custom Membership/Role providers, in particular if your authn/authz model doesn't quite fit the mold of those providers.</p> <p>First, you should realize that you don't need to write everything from scratch, you can use the core Forms authentication API, <em>which can be used independently</em> of the Membership/Role provider framework:</p> <ul> <li><code>FormsAuthentication.SetAuthCookie</code> - Call this after user has been authenticated, specify the user name</li> <li><code>Request.IsAuthenticated</code> - Returns true if SetAuthCookie was called</li> <li><code>HttpContext.Current.User.Identity.Name</code> - Returns the user name specified in the call to SetAuthCookie</li> </ul> <p>So here is what you do in MVC to bypass the Membership/Role provider:</p> <ol> <li><p><strong>Authentication</strong>: In your controller, authenticate the user using your custom logic.If successful, call <code>FormsAuthentication.SetAuthCookie</code> with the user name.</p></li> <li><p><strong>Authorization</strong>: Create a custom authorize attribute (deriving from AuthorizeAttribute) . In the <code>AuthorizeCore</code> override, implement your custom authorization logic, taking the user in <code>HttpContext.Current.User.Identity.Name</code> and the roles defined in the Roles property of the AuthorizeAttribute base class. Note you can also define properties on your custom authorization attribute and use that in your authorization logic. For example you can define a property representing roles as enumerated values specific to your app, instead of using the Roles property which is just a string.</p></li> <li><p>Affix your controllers and actions with your custom authorize attribute, instead of the default Authorize attribute.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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.
    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