简体   繁体   中英

Asp.net : How to deny a page to be accesed by users and set permissions?

I have some asp.net pages , and I want to deny them to be accessed by direct link . So I need to make a page to by accessed only by administrators and a page that will be accesed by logged users.

How can I do that? can someone explain or show a good example?

Thank you

You can create a folder with pages that needs to be accessed by set of users. Inside the folder you can create web.config with restriction.

eg.<configuration>
  <system.web>
    <authorization>
      <deny users="user1,user2" />
      <allow users="*" />
    </authorization>
  </system.web>
</configuration>

You can find more about ASP.NET Security

Update

On successful login you can add the users to a specific role.

eg. you assigned to the role users

then you can modify the web.config

 <authorization> 
            <allow roles="users" />
            <deny users="*" /> 
  </authorization> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM