我正在使用以下代码在当前 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"];
但我无法获得查询字符串的值(此处为用户 ID)并获得空值。
为什么?
请帮忙