How to authorize roles with ASP.NET Identity in Web Forms?

送分小仙女□ 提交于 2020-01-14 02:34:09

问题


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>


来源:https://stackoverflow.com/questions/21243733/how-to-authorize-roles-with-asp-net-identity-in-web-forms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!