Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a sample web.config, if you placed this file within a folder (within the structure of your web project) where you only want to allow users with the "Admin" Role (for example) this will do the job. </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;appSettings/&gt; &lt;connectionStrings/&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow roles="Admin"/&gt; &lt;deny users="*"/&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <p>In order to link this to your security, after a successful login check you need to create a FormsAuthenticationTicket and pass in details like the user name and user roles.</p> <p>A simple example showing this is:</p> <pre><code> FormsAuthenticationTicket myTicket = new FormsAuthenticationTicket(1, myUserName, DateTime.Now, DateTime.Now.AddMinutes(30), true, myUserRole, FormsAuthentication.FormsCookiePath); string hash = FormsAuthentication.Encrypt(myTicket); HttpCookie myCookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); Response.Cookies.Add(myCookie); </code></pre> <p>That way you can do this in your code:</p> <pre><code> if (Context.User.IsInRole("Admin")) { // Do Something } else { // Do Something Else } </code></pre> <p>And your Web.config file will work as I detailed above.</p> <p>More info on FormsAuthenticationTickets here <a href="http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx</a></p>
    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.
 

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