我使用以下代码在当前的http上下文中设置URL
public HttpContext SetNewHttpContext(string uRL)
{
var httpRequest = new HttpRequest("", uRL, "");
var httpResponse = new HttpResponse(new StringWriter());
return new HttpContext(httpRequest, httpResponse);
}
在
下调用它HttpContext.Current = SetNewHttpContext("http://root/test.aspx?userid=319279549&name=xyz");
var val = HttpContext.Current.Request.QueryString["userid"];
但我无法获取查询字符串的值(此处为userid)并且为null。
为什么?
请帮忙
答案 0 :(得分:1)
Uri tempUri = new Uri("http://root/test.aspx?userid=319279549&name=xyz");
string sQuery = tempUri.Query;
NameValueCollection queryString =
System.Web.HttpUtility.ParseQueryString(sQuery ,Encoding.UTF8);