1
在web.config中:如何使用customErrors捕获异常?
<customErrors mode="RemoteOnly" defaultRedirect="~/Errors.aspx">
<error statusCode="404" redirect="~/Error.aspx?code=404"/>
</customErrors>
在后面页面的代码:
throw new HttpException(404, "404 Not Found");
在此行中,用一个错误的Visual Studio游:
System.Web.HttpException was unhandled by user code
我应该在哪里赶上这个错误?
这个,不错。我接受这个答案之前的另一个问题是:是否可以将字符串参数“404 Not Found”传递给重定向页面? – mariki 2010-02-23 17:06:27
不容易。如果这是您的要求,我会绕过customErrors并在global.asax中的Application_Error中编写我自己的异常处理程序。 – 2010-02-23 17:31:51
如果我使用Application_Error,我应该禁用customErrors? – mariki 2010-02-23 17:49:09