tags:

views:

60

answers:

3

Hi all,

I set a custom 404 error page in IIS6. In code-behind i want to get parameters from incorrect URL, How do i do?

A: 

You might want to consider "accepting" the correct answers for all the questions you've asked (see the FAQ about how this site governs itself.) Hopefully, my answer is one of them:

You can grab that value in Global.asax in the Application_OnError handler:

void Application_Error(object sender, EventArgs e) 
{
     string s = System.Web.HttpContext.Current.Request.QueryString.ToString();
}

Or deal with each of the QueryString values separately via QueryString.Keys[], etc.

LesterDove
When i am debugging in my custom 404 error page, i don't see any parameters which i want to get in all parameters are contained by Request object.
Linh
+1  A: 

I guess you might use

Request.ServerVariables("HTTP_REFERER");

in your custom error page to get from where it has been redirected. If you get the page then you can also get querystring parameters.

hope this helps

A Bright Worker
A: 

In your custom 404 page, check the Request.Url.Query. The query string should be in the form: 404;old request url goes here.

Strip out the 404; part, and create a new Uri object with this data.. Congrats - you have access to the old url, and can easily get the query string params :)

For example:

var url = new Uri(HttpUtility.UrlDecode(Request.Url.Query));
if (url.Query.Length > 0)
{
    var parameters = url.Query.TrimStart('?').Split('&');
    foreach(var p in parameters)
    {
        var parts = p.Split(new[]{'='}, 2).Dump();
        var name = parts[0];
        var value = parts[1];
    }
}
Artiom Chilaru