2009-08-12 37 views
0

我試圖做一個基於404的URL重寫。我的邏輯檢查「aspxerrorpath」,但它總是顯示爲空。我的代碼在開發服務器上工作得很好。我有客戶打開。我也有在IIS控制面板指向我的處理程序的顧客。關於爲什麼它不通過404網址的想法?aspxerrorpath NULL在IIS 6

public class UrlHandler : Handler301 
{ 
    protected override string getRedirectionUri() 
    { 
     HttpContext.Current.Response.ContentType = "text/plain"; 

     String request = HttpContext.Current.Request.QueryString["aspxerrorpath"]; 
     if (request != null) 
     { 
      SomeUrl url = getUrlLogic(); 

      if (url != null) 
      { 
       return url.ReferencedUrl; 
      } 
      else 
      { 
       return ConfigurationManager.AppSettings["404RedirectionUri"]; 
      } 
     } 
     else 
     { 
      String site = HttpContext.Current.Request.Url.AbsoluteUri; 

      return site.Substring(0, site.LastIndexOf('/')); 
     } 
    } 
} 

回答

0

原來IIS做它的查詢字符串不同於開發服務器:??

String request = HttpContext.Current.Request.QueryString["aspxerrorpath"]; 

if (StringUtils.isNullOrEmpty(request)) 
{ 
    String rawUrl = HttpContext.Current.Request.RawUrl; 

    if (rawUrl.Contains("?404")) 
    { 
     request = rawUrl.Substring(rawUrl.LastIndexOf('/')); 
    } 
} 

它使用查詢字符串,而不是aspxerrorpath查詢字符串ASP.NET開發服務器使用。