开发者

how to restric user of Certain role from certain page in Asp.net C#

开发者 https://www.devze.com 2023-01-08 15:50 出处:网络
I am using built-in asp.net Roles and membership provider in my website. what i want to restrict all user who is in role \"Nurse\" from page n开发者_C百科ame

I am using built-in asp.net Roles and membership provider in my website.

what i want to restrict all user who is in role "Nurse" from page n开发者_C百科ame

doctorDiscussionBoard.aspx.

help me how to do it.

i guess we will write the code in Page load method.


You can do it like you suggest:

if (User.IsInRole("Nurse"))
    //Redirect

That method is in the System.Security.Principal namespace.

You can also do it in the web.config:

<configuration>
  <location path="doctorDiscussionBoard.aspx">
    <system.web>
      <authorization>
        <deny roles="Nurses" />
        <allow roles="Doctors" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>
....
0

精彩评论

暂无评论...
验证码 换一张
取 消