2014-01-10 45 views
1

在我的MVC应用程序中,我启用了web.config中的自定义错误。我希望所有错误都能重定向到一个页面。自定义错误适用于错误,但在404上失败

<customErrors mode="On" redirectMode="ResponseRewrite" /> 

这重定向到~/Views/Shared/Error.cshtml页面就好了,当我做

throw new Exception(); 

但是,当我冲浪site/Home/Bla它重定向我的IIS一般的404错误页面,而不是我的自定义一个。

我试图

private void Application_Error(object sender, EventArgs e) 
{ 
    Response.TrySkipIisCustomErrors = true; 
} 

添加到Global.asax,但无济于事。

有谁知道可能是什么问题? (如果您需要了解更多信息,然后AKS就必领受。)

+0

以下是使用通用错误控制器的方法:http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4?rq= 1 –

回答

1

我已经找到了问题。感谢Jason给我指出了正确的方向。 :)感谢他,我找到了正确的道路。在StackOverflow page

发现

答案显然我指着一个控制器和一个动作,如果在customErrors节点上指定redirectMode="ResponseRewrite",然后重定向使用旧版库获取内容。这应该是一个页面,不能是一个mvc路线。

因此,要么指定实际页面,要么使用redirectMode="ResponseRedirect"选项。该页面需要是.htm或.html页面,.cshtml也不被接受。

+0

+1:感谢您发布您的解决方案。我希望更多的人会这样做。 –

+1

我知道,我也是。这就是为什么我确保当我发布问题时,我会检查回来,直到我得到答案并更新它。而且我不害怕在应有的地方给出信用。 :) –

1

尝试添加该到你的web.config

<customErrors mode="On" /> 

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <!-- Avoid IIS messing with custom errors http://stackoverflow.com/a/2345742/426840 --> 
    <httpErrors existingResponse="PassThrough" /> 

    </system.webServer>