Code Snippet posted by:
Niladri.Biswas | Posted on: 4/16/2012 | Category:
ASP.NET Codes | Views: 743 | Status:
[Member] |
Points: 40
|
Alert Moderator
Write the below function
public HttpContext SetNewHttpContext(string uRL)
{
var httpRequest = new HttpRequest("", uRL, "");
var httpResponse = new HttpResponse(new StringWriter());
return new HttpContext(httpRequest, httpResponse);
}
Invoke it as under
var oldURL = HttpContext.Current.Request.Url;
HttpContext.Current = SetNewHttpContext("http://root/test.aspx?userid=319279549&name=xyz");
var newURL = HttpContext.Current.Request.Url;
N.B.~ If we want to read the query string value, we can do so by
var queryString = System.Web.HttpUtility.ParseQueryString(newURL.Query, Encoding.UTF8);
var valUserName = queryString["name"];
Hope this helps
Best Regards,
Niladri Biswas