2014-03-26 65 views
0

我希望登錄頁面成爲我的網站www.mysite.com/(默認路徑)的根目錄,然後將所有其他文件夾/需要用戶在下面的頁面在登錄ASP.NET web.config授權 - 允許訪問根目錄但不能訪問子文件夾/頁面

有什麼比使用以下內容作爲全球規則,然後下一個位置元素指定拒絕規則爲每一個孩子更簡單的方法:

<authorization> 
    <allow users="?"/> 
</authorization> 

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

是的..創建一個授權過濾器.. – Shaz

回答

0

嘗試此代碼在您的母版頁

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"); 
     } 
    } 
相關問題