Asp.net mvc 3 显示MVC 3的内置错误视图
我遵循了这一点,但我仍然收到ASP.NET屏幕上的提示:打开错误执行此操作,或显示自定义错误页面执行此操作 我已经注册了HandleErrorAttribute,并在web.config中添加了Asp.net mvc 3 显示MVC 3的内置错误视图,asp.net-mvc-3,Asp.net Mvc 3,我遵循了这一点,但我仍然收到ASP.NET屏幕上的提示:打开错误执行此操作,或显示自定义错误页面执行此操作 我已经注册了HandleErrorAttribute,并在web.config中添加了。该属性直接位于控制器类签名之前的行上 我还缺什么吗 编辑 我按照您的建议从类中删除了该属性,结果就是这样。我想没什么特别的 web.config </appSettings> <system.web> <customErrors mode="On" />
。该属性直接位于控制器类签名之前的行上
我还缺什么吗
编辑
我按照您的建议从类中删除了该属性,结果就是这样。我想没什么特别的
web.config
</appSettings>
<system.web>
<customErrors mode="On" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
错误*
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
“/”应用程序中出现服务器错误。
运行时错误
描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止查看应用程序错误的详细信息。
详细信息:若要在本地服务器计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建一个标记。然后,该标记的“mode”属性应设置为“RemoteOnly”。要在远程计算机上查看详细信息,请将“模式”设置为“关闭”。
注意:通过修改应用程序配置标记的“defaultRedirect”属性以指向自定义错误页URL,可以将当前看到的错误页替换为自定义错误页。
这对我和其他许多人都有效。测试一下。可能对您也有帮助。如果您希望看到自定义错误页面(您自己设计的页面),则需要实际创建该页面并在customErrors元素中引用
<customErrors defaultRedirect="GenericError.htm" mode="On" />
在上面的示例中,您将在web应用程序中创建GernericError.htm页面。如果出现错误,将显示此信息
如果您想查看抛出的实际异常的详细信息,则需要将模式设置为mode=“Off”
或mode=“RemoteOnly”
此外,请确保您在IIS中为应用程序运行正确版本的asp.net(即asp.net 4.0),否则您的web.config文件可能无法正确解析,导致出现此页面。您遇到了什么样的错误?使用该属性时,默认情况下不会处理某些错误。如示例所示,我使用DivideByZeroException对其进行了测试。我不明白您所说的属性位于控制器类签名之前的线上是什么意思。如果您使用的是golobal过滤器,则不需要类上的属性。在global.asax(应用程序_Start()和RegisterGlobalFilters)和web.config的相关部分向我们展示您的代码。@MystereMan,请参阅上面的编辑。抱歉,没有先看教程,以了解您试图做什么。因此,现在的问题是MVC应用程序是否正确显示了任何视图?所有其他视图都正确显示。我确信错误视图会正确显示,但它没有达到这一点,我正在从HandleError属性中寻找内置功能。
<customErrors defaultRedirect="GenericError.htm" mode="On" />