我有以下設置在我的ASP.NET MVC應用程序的web.config錯誤頁面:麻煩ASP.NET MVC應用程序重定向到未經授權的用戶
<authentication mode="Windows" />
<authorization>
<allow roles="MySecurityGroup"/>
<deny users="*"/>
</authorization>
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="401" redirect="Help.aspx"/>
</customErrors>
一切工作正常,如果您位於MySecurityGroup中,但如果您不是,則不會將其重定向到Error.aspx或Help.aspx。 (請注意,Error.aspx住在查看\共享,而Help.aspx在視圖\首頁。)所有你得到的是默認的錯誤:
Server Error in '/' Application.
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
我在做什麼錯?
UPDATE:現在我的web.config設置像這樣,它仍然沒有工作:
<system.web>
<customErrors mode="On" defaultRedirect="Help.aspx">
</customErrors>
</system.web>
<location path="">
<system.web>
<authorization>
<allow roles="MySecurityGroup"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<location path="Help">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
注意,我可以導航到MyApp的/幫助就好了我正確地從其餘被取締的網站,但它永遠不會自動重定向到幫助頁面。
完美的感覺,但由於某種原因,這不適合我。我在原始部分關閉後立即輸入了該代碼,但我沒有得到任何不同的結果。爲了簡單起見,我甚至不用擔心Help.aspx,只是Error.aspx。 –
gfrizzle
2009-06-16 17:53:11