Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 8670 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Set URL in HttpContext ...
Niladri.Biswas

Set URL in HttpContext

 Code Snippet posted by: Niladri.Biswas | Posted on: 4/16/2012 | Category: ASP.NET Codes | Views: 743 | Status: [Member] | Points: 40 | Alert Moderator   
Ads

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
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 2:52:12 PM