简体   繁体   中英

Restrict roles for specific folder with web.config

I'm using this code for authenticating in web.config

   <authentication mode="Forms">
      <forms timeout="2000" name="A" loginUrl="login.aspx" protection="None" path="/"></forms>
    </authentication>

and use this web.config in each folder

<?xml version="1.0"?>
<configuration>
    <system.web>
      <authorization>
        <allow roles="Admin"/> // or other roles in different pages
      </authorization>
    </system.web>
</configuration>

When user without Admin Role wants to open this page , automatically redirect to "login.aspx"

Is it possible to redirect to other page like "access-denied.aspx"

Try this and let me know what happens?

<system.web>
      <authorization>
        <allow roles="Admin"/> // or other roles in different pages
        <deny users ="*" />
      </authorization>
</system.web>

Add this code to login page:

if (!IsPostBack)
{
     if (User.Identity.IsAuthenticated)
     {
           if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
            {
                 Response.Redirect("~/Admin/AccessDenied.aspx");
             }
     }

}

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