Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have solved this exact problem. In the following manner:</p> <p><code>web.config</code>:</p> <pre><code>&lt;authentication mode="Forms"&gt; &lt;forms name="APPAUTH" defaultUrl="/webapp/Home.mvc" loginUrl="/webapp/Session.mvc/Login" protection="All" timeout="30" path="/"/&gt; &lt;/authentication&gt; &lt;authorization&gt; &lt;deny users="?"/&gt; &lt;/authorization&gt; &lt;location path="Session"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow users="*"/&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/location&gt; </code></pre> <p>Then I hook <code>Application_AuthenticateRequest</code> something along the lines of:</p> <pre><code>protected void Application_AuthenticateRequest(Object sender, EventArgs e) { string cookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = Context.Request.Cookies[cookieName]; if (null == authCookie) { //no authentication cokie present return; } FormsAuthenticationTicket authTicket = null; try { authTicket = FormsAuthentication.Decrypt(authCookie.Value); } catch (Exception) { // Can't do anything if we can't decrypt the ticket so treat it as not there FormsAuthentication.SignOut(); // Remove bad ticket } if (authTicket == null) { //could not decrypt cookie return; } // get the role string[] roles = authTicket.UserData.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); // Set the security context ISecurityService security = ContainerProvider.RequestContainer.Resolve&lt;ISecurityService&gt;(); Models.User user = security.GetUser(authTicket.Name); if (user == null) { FormsAuthentication.SignOut(); throw new HttpException((int)System.Net.HttpStatusCode.Unauthorized, "Session expired!"); } AppIdentity id = new AppIdentity(user, !authTicket.Expired); AppPrincipal principal = new AppPrincipal(id, roles); Context.User = principal; } </code></pre> <p>The <code>ContainerProvider.RequestContainer.Resolve&lt;ISecurityService&gt;();</code> call is to a <a href="http://code.google.com/p/autofac/" rel="nofollow noreferrer">Autofac</a> container, but you can do anything you need to / want to here.</p> <p>The <code>AppIdentity</code> and <code>AppPrincipal</code> classes are custom so I can access my roles, but they are not that complicated.</p>
    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. This table or related slice is empty.
    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