【问题标题】:Restrict roles for specific folder with web.config使用 web.config 限制特定文件夹的角色
【发布时间】:2012-03-25 20:56:02
【问题描述】:

我在 web.config 中使用此代码进行身份验证

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

并在每个文件夹中使用此 web.config

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

当没有Admin Role的用户想要打开这个页面时,自动重定向到“login.aspx”

是否可以重定向到“access-denied.aspx”等其他页面

【问题讨论】:

    标签: asp.net authentication web-config


    【解决方案1】:

    试试这个,让我知道会发生什么?

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

    将此代码添加到登录页面:

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

    【讨论】:

    • 谢谢Praneeth,但我想在不使用代码的情况下处理这个问题,
    猜你喜欢
    • 2018-05-07
    • 2012-02-04
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多