1

我正在使用以下代码在当前 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)并获得空值。

为什么?

请帮忙

4

1 回答 1

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);
于 2012-04-16T12:21:23.643 回答