代码之家  ›  专栏  ›  技术社区  ›  Wayne Hartman

IIS 6上的aspxerrorpath为空

  •  0
  • Wayne Hartman  · 技术社区  · 16 年前

    我正在尝试基于404进行URL重写。我的逻辑检查“aspxerrorpath”,但它始终显示为空。我的代码在dev服务器上运行良好。我打开了客户机。在IIS控制面板中,我还有一些客户错误指向我的处理程序。为什么不传递404 URL????

    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('/'));
            }
        }
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Wayne Hartman    15 年前

    结果表明,IIS的查询字符串与dev服务器不同:

    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('/'));
        }
    }
    

    它使用 ?四百零四 查询字符串而不是 ?ASPXErrPrPATH ASP.NET开发人员服务器使用的查询字符串。

    推荐文章