我正在尝试在 IIS(和 Azure)下处理 404 错误,但下面的代码不起作用。在本地主机上,这很好用。我应该怎么做才能解决这个问题?
来自http模块
protected void Application_Error(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
Exception ex = application.Server.GetLastError().GetBaseException();
if (ex != null && ex is HttpException)
{
var httpEx = ex as HttpException;
if (httpEx != null && httpEx.GetHttpCode() == 404)
{
context.Response.StatusCode = 404;
application.Response.Redirect(BXSite.Current.GetUrl("/404/"));
application.Server.ClearError();
}
}
}