ASP.NET Membership Roles Web.config settings

假装没事ソ 提交于 2019-12-30 11:12:13

问题


I want to understand how the system.web authorization tag on the web.config works, and what exactly each attribute and property does.

For instance, what does

  <system.web>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>
  </system.web>

Specifically what I want to do is to disallow access to most of the site for unauthenticated users, allow access to some of the site for authenticated users who belong to a certain role, and allow full access to users from a second role.


回答1:


<system.web>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>
</system.web>`

This will allow access to anyone who is logged in.

<deny users="?"/> denies access to any anonymous users - users who have not logged in and then <allow users="*"/> will allow access to all other users, which in this case is all authenticated users.

If this is in your main web.config file this will apply site wide. If you want to have different levels of access you can use the <location> tag:

<location path="~/Admin">
 <system.web>
   <authorization>
     <allow roles="Admin"/>
     <deny users="*"/>
   </authorization>
 </system.web>

This will restrict access to any files/folders in the admin folder to users in the "Admin" role.




回答2:


Nevermind, found it on msdn:

Authorization Element
Allow Element
Deny Element



来源:https://stackoverflow.com/questions/4280184/asp-net-membership-roles-web-config-settings

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