麻烦ASP.NET MVC应用程序重定向到未经授权的用户

问题描述:

我有以下设置在我的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的/帮助就好了我正确地从其余被取缔的网站,但它永远不会自动重定向到帮助页面。

您必须明确地将其他组的访问权限授予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

你想通过mvc或asp.net处理错误和帮助页吗?目前,您正在将页面视为mvc视图,但您已重定向映射到asp.net管道的URL。在猜测移动错误和帮助到网站的根目录,它应该工作