0
我想知道哪種方式更安全地拒絕頁面訪問。我知道其中的一個文件夾訪問。我不需要文件夾。Asp.net路徑訪問
1路
<location path="xfile">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
或 2路
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
Response.Redirect("/Login");
}
else
{
if (User.IsInRole("admin"))
{
// my action
}
else
{
Response.Redirect("/");
}
}
}
還得我用文件夾的安全性? 或2.方法是不安全的?
謝謝,我知道這一點,但我想學哪一個更好。 – serdar
更好的是取決於你有什麼要求。在一個簡單的情況下,您應該啓用表單身份驗證並將loginUrl設置爲包含登錄表單的頁面。然後在web.config中設置授權規則 –