2012-07-17 70 views
0

我想在IIS(和Azure)下处理404错误,但下面的代码不起作用。 在本地主机上,这工作得很好。 我该如何解决这个问题?404例外(IIS)

从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(); 
     } 
    } 
} 
+0

我相信这个链接会引导你 http://stackoverflow.com/questions/10059009/enable-custom-errors-in-azure – Madan 2012-07-17 12:36:15

+0

你是什么意思不工作?你看到任何错误消息? – 2012-07-19 14:43:04

回答

0

我只是说“假”重定向功能的第二个参数和重定向开始作品的权利。 像这样: application.Response.Redirect(“/ 404 /”,false)。