如何在本地主机上 运行 时禁用我的 global.asax Application_Error 子?
How can I disable my global.asax Application_Error sub when running on localhost?
正如标题所说,我试图避免在调试时由 global.asax 页面处理错误,同时在部署到网站后仍然处理它们。
最简单的选择是在我们调试时注释掉子项,但在第 5 次之后有人忘记在复制之前撤消它,我正在寻找替代方案。
这里有一个例子
protected void Application_Error(object sender, EventArgs e)
{
#if DEBUG
var httpContext = ((Application)sender).Context;
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.TrySkipIisCustomErrors = true;
httpContext.Server.TransferRequest(yourUrl, true);
#else
your code to handle error;
#endif
}
正如标题所说,我试图避免在调试时由 global.asax 页面处理错误,同时在部署到网站后仍然处理它们。
最简单的选择是在我们调试时注释掉子项,但在第 5 次之后有人忘记在复制之前撤消它,我正在寻找替代方案。
这里有一个例子
protected void Application_Error(object sender, EventArgs e)
{
#if DEBUG
var httpContext = ((Application)sender).Context;
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.TrySkipIisCustomErrors = true;
httpContext.Server.TransferRequest(yourUrl, true);
#else
your code to handle error;
#endif
}