快速关闭CustomErrors以进行生产和开发

时间:2013-04-04 20:28:17

标签: asp.net web-services exception-handling custom-error-pages custom-errors

我开发了很多ASP.NET Web表单。在测试期间,我关闭了customErrors,然后在将表单移动到生产环境中时出现ResponseRedirect自定义错误。

我想知道我是否可以通过更改设置值来完成此操作来简化我的开发。

我想要的是将我的Properties.Settings.Default.TestMode值从开发人员更改为生产,然后启用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设置完成所有工作就会很棒。

1 个答案:

答案 0 :(得分:1)

您想要了解 Web.Config Transformation 。它允许您独立设置开发和生产的特定设置。

以下是Microsoft的一个很好的演练:How to: Transform Web.config When Deploying a Web Application Project