2

我有以下設置在我的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的/幫助就好了我正確地從其餘被取締的網站,但它永遠不會自動重定向到幫助頁面。

回答

1

您必須明確地將其他組的訪問權限授予Error.aspx和/或​​Help.aspx,以便他們可以實際訪問頁面。您現在設置的方式,只有MySecurityGroup用戶才能進入頁面。

你需要這樣的事:

<location path="Error.aspx"> 
<system.web> 
    <authorization> 
    <allow users="*"/> 
    </authorization> 
</system.web> 
</location> 

與同爲Help.aspx。或者,您可以在文件夾級別執行此操作。

+0

完美的感覺,但由於某種原因,這不適合我。我在原始部分關閉後立即輸入了該代碼,但我沒有得到任何不同的結果。爲了簡單起見,我甚至不用擔心Help.aspx,只是Error.aspx。 – gfrizzle 2009-06-16 17:53:11

0

你想通過mvc或asp.net處理錯誤和幫助頁嗎?目前,您正在將頁面視爲mvc視圖,但您已重定向映射到asp.net管道的URL。在猜測移動錯誤和幫助到網站的根目錄,它應該工作

相關問題