ASP.网网络.配置授权-允许访问根目录,但不允许访问子文件夹/页面



我希望登录页面是我的网站www.mysite.com/(默认路由)的根,然后有所有其他文件夹/页面下面,需要用户登录。

使用以下规则作为全局规则,然后在location元素下为每个子元素指定一个拒绝规则,还有比这更简单的方法吗?

<authorization>
  <allow users="?"/>
</authorization>
<location path="/SubFolder1"> <!-- repeat for each child -->
   <system.web>
      <authorization>
         <deny users="?"/>
      </authorization>
   </sysetm.web>
</location>

在您的母版页中试试这段代码

 protected void Page_Init(object sender, EventArgs e)
    {
        CheckAuthentication();
    }
    //Check if the user is authenticated 
    private void CheckAuthentication()
    {
        if (!Context.User.Identity.IsAuthenticated)
        {
            Response.Redirect("~/Login.aspx");
        }
    }

最新更新