[英]Redirect not logged in users to login page on unauthorized access to folder ManagerPages
這是我默認得到的:
HTTP錯誤404.0-找不到所需的資源已被刪除,名稱已更改或暫時不可用。
Requested URL htt p://localhost:56335/Account/Login?ReturnUrl=%2fManagerPages%2fVideoManager.aspx
Physical Path c:\users\pc\documents\visual studio 2012\Projects\Lab8\Lab8\Account\Login
Logon Method Anonymous
Logon User Anonymous
Request Tracing Directory C:\Users\Pc\Documents\IISExpress\TraceLogFiles\LAB8
我嘗試過:
<customErrors defaultRedirect="Error.aspx" mode="On">
<error statusCode="401" redirect="Account/Login.aspx" />
<error statusCode="404" redirect="Forbidden.aspx" />
</customErrors>
但是,沒有成功,就像我什么都沒改變一樣。 我還嘗試了在stackoverflow,google上找到的幾乎所有解決方案,但是無論我做什么,此頁面始終會出現。 該代碼甚至都沒有進入代碼隱藏,因此如何重定向它們? 也許是會員?
Edit:
我在瀏覽器地址選項卡中用Login.aspx替換了Account / Login,它運行良好。 如何用代碼替換它?
我嘗試了<rewrite>
標記,並在更改URL以匹配錯誤的路徑“ Account/Login
”時使其起作用:
<system.webServer>
<rewrite>
<rules>
<rule name="Unauthorized access" stopProcessing="true">
<match url="Account/Login" />
<action type="Redirect" url="/Login.aspx"/>
</rule>
</rules>
</rewrite>
</system.webServer>
現在,它不僅重定向到“ Login.aspx
”,而且還具有原始查詢字符串: Login.aspx?ReturnUrl=%2fManagerPages%2fVideoManager.aspx
<authentication mode="Forms">
<forms name="DForm" loginUrl="/login.aspx" />
</authentication>
.....
<location path="ManagerPages">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.