mvc中的自定义错误页面

San*_*osh 3 asp.net-mvc

我需要使用customerror来显示错误页面 web.config

但是watever错误可能是,即使在web.config我指定了一些版本错误也需要显示错误页面,

我怎样才能做到这一点.我试过但是url重定向到

"http://localhost:1966/Error.html?aspxerrorpath=Error.html"
Run Code Online (Sandbox Code Playgroud)

CustomError标签:

<customErrors mode="On" defaultRedirect="Error.html" />
Run Code Online (Sandbox Code Playgroud)

并显示来自mvc的另一个错误页面,而不是地雷.

Mar*_*ann 7

在ASP.NET MVC中,通常使用HandleError属性指定错误处理.默认情况下,它使用名为"错误"的视图来显示自定义错误页面.如果您只想自定义此视图,则可以编辑Views/Shared/Error.aspx.

如果在特定情况下需要不同的View,则可以显式提供View属性.

以下是具有自定义错误视图的Controller操作示例:

[HandleError(View = "CustomError")]
public ViewResult Foo() 
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

有关ASP.NET MVC中的全局错误处理,请参阅此文章.