I set a custom 404 error page i开发者_C百科n IIS6. In code-behind i want to get parameters from incorrect URL, How do i do?
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
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.
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];
}
}
精彩评论