Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manage Roles in asp.net using FORMS
    primarykey
    data
    text
    <p>So I'm making a login system for my asp.net site. There are 3 different types of users. I've discovered that FORMS can manage roles so I decided to try this.</p> <p>I have everything working with authentication in FORMS currently - but without roles. I found this piece of code that should limit access to a specific page. But everyone can still access that page. which is odd because I haven't added anyone to the role "member". to start off with I only added 1 role to see if people were blocked from the page.</p> <pre><code> &lt;configuration&gt; &lt;connectionStrings&gt; //EDITED &lt;/connectionStrings&gt; &lt;system.web&gt; &lt;roleManager enabled="true" /&gt; &lt;customErrors mode ="Off"&gt; &lt;/customErrors&gt; &lt;authentication mode="Forms"&gt; &lt;forms name=".ASPXAUTH" loginUrl="login.aspx" protection="All" timeout="30" path="/"&gt; &lt;/forms&gt; &lt;/authentication&gt; &lt;authorization&gt; &lt;deny users="?" /&gt; &lt;allow users="*" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;location path="RandomPage.aspx"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow roles="Member" /&gt; &lt;deny users="*" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/location&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>Code for adding the roles to FormsAuthenticationTicket. P.Userole contains the string"Member"</p> <pre><code>FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, //Ticket version p.firstName, //username DateTime.Now, DateTime.Now.AddMinutes(30), false, //true for persistant user cookie p.userRole+"", FormsAuthentication.FormsCookiePath); string hashCookies = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies); Response.Cookies.Add(cookie); Response.Redirect("Default.aspx"); </code></pre>
    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.
 

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