How to save URL parameters when writing custom 404 error page?

I installed a custom 404 error page in IIS6. In encoding, I want to get parameters from the wrong URL. How can i do this?

+3
source share
3 answers

I think you could use

Request.ServerVariables("HTTP_REFERER");

on the user error page to go from where it was redirected. If you get a page, you can also get request parameters.

hope this helps

+1
source

, "" , (. FAQ , .) , :

Global.asax Application_OnError:

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

QueryString QueryString.Keys [] ..

0

In your 404 user page check Request.Url.Query. The request line should be in the form: 404, here the old request URL is sent.

Remove 404; part and create a new Uri object with this data. Congrats - you have access to the old URL and you can easily get query string parameters :)

For instance:

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];
    }
}
0
source

Source: https://habr.com/ru/post/1741381/


All Articles