How to authorize roles with ASP.NET Identity in We

2019-05-21 02:53发布

问题:

How do I authorize a page to only signed in users that are in a certain role? I am not using MVC, I cannot use the [Authorize(Roles="Admin")] attribute.

回答1:

You would use the Web.config to configure access:

<configuration>
     <!-- Allow only Administrators to visit RoleBasedAuthorization.aspx -->    
     <location path="RoleBasedAuthorization.aspx">    
          <system.web>    
               <authorization>    
                    <allow roles="Administrators"/>
                    <deny users="*" />
               </authorization>    
          </system.web>    
     </location>    
</configuration>