【发布时间】:2013-03-27 02:39:01
【问题描述】:
我开发了很多 ASP.NET Web 表单。在测试期间,我关闭了 customErrors,然后当我将表单移入生产环境时出现 ResponseRedirect 自定义错误。
我想知道是否可以通过更改设置值来简化我的开发。
我想要的只是将我的 Properties.Settings.Default.TestMode 值从 developer 更改为 production 并打开 customError。
所以我想我的 Global.asax.cs 代码可能如下所示:
protected void Application_Error(object sender, EventArgs e) {
if (Properties.Settings.Default.TestMode == "production") {
Server.ClearError();
Response.Redirect("errorpage.htm");
}
else {
// Not sure what it would do here. Nothing?
}
}
但是我不确定我的 Web.config 文件中会包含什么内容。 CustomErrors 如下所示。
<!--<customErrors mode="Off" />-->
<customErrors mode="On" defaultRedirect="ErrorPage.htm" redirectMode="ResponseRedirect"/>
现在我只是注释掉/在我需要做出改变的地方。我觉得我一直都在这样做,如果让我创建的 TestMode 设置来完成所有工作,那就太好了。
【问题讨论】:
-
您是否尝试过将 customErrors 模式设置为 RemoteOnly?我相信您知道,这会为(顾名思义)远程连接启用自定义错误,但如果您从本地服务器/机器进行测试,那么您将绕过自定义错误。
-
我确实遇到了这个解决方案,但我不喜欢它的原因是因为我需要在远程系统上测试许多功能才能工作,所以我几乎没有在本地机器上测试过某一点。一个例子是发送电子邮件......我的机器在我们的网络上被阻止这样做,而远程测试服务器则没有。
标签: asp.net web-services exception-handling custom-error-pages custom-errors