using multiple authorization elements in web.confi

2019-07-20 12:24发布

Is it possible to use multiple authorization elements in a single web.config to allow additional users access to one file?

E.g., I would like to allow User1 access to the whole application (including Page1.aspx), and User2 access to only Page1.aspx:

<system.web>
  <authorization>
    <allow users="DOMAIN\User1" />
    <deny users="*" />
  </authorization>
</system.web>
<location path="~/Page1.aspx">
  <system.web>
    <authorization>
      <allow users="DOMAIN\User2" />
      <deny users="*" />
    </authorization>
  </system.web>
</location>

2条回答
神经病院院长
2楼-- · 2019-07-20 12:59

I believe you can use a comma delimited list of users, so there should be no need for using multiple authorization elements for a single resource.

Also, it is generally better to rely on roles instead of specific users. Since it appears you are using AD, then you can use a security group or something similar for the roles.

查看更多
姐就是有狂的资本
3楼-- · 2019-07-20 13:08

If you remove the <deny users="*" /> from the Page1.aspx authorization section, you should get what you want. It will allow User2 to use just that page, and User1's authorization to everything will still apply to this page as well.

Here's a pretty good tutorial on all things related to authorization.

查看更多
登录 后发表回答