views:

181

answers:

1

I'm trying to do a URL rewrite based off a 404. My logic checks for the "aspxerrorpath", but it always shows up as null. My code works perfectly fine on the dev server. I have customerrors turned on. I also have customerrors in the IIS control panel pointing to my handler. Ideas on why it is not passing the 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('/'));
        }
    }
}
A: 

Turns out IIS does its query string differently than the dev server:

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

It uses the ?404 query string instead of the ?aspxerrorpath query string that the ASP.NET dev server uses.

Wayne Hartman