我正在寻找一种方法来访问Web服务中标准ASP.NET请求对象中包含的.net查询字符串。换句话说,如果我将SOAP Web服务设置为此URL:

http://localhost/service.asmx?id = 2

我可以访问ID Get变量吗?

有帮助吗?

解决方案

我只是寻找<!>引用;请求<!>引用; asmx文件中的上下文,我看到了。但我不确定它是否正确。

this.Context.Request.QueryString["id"];

其他提示

HttpContext.Current.Request.QueryString [QUOT <!>; <!> ID QUOT;]

既然你问,我猜没有HttpContext.Current.Request?

在寻找同一问题的解决方案时,我决定采取不同的方法。 我的查询字符串包含大量变量,因为我无法从Web服务访问查询字符串数据,我也不想将每个查询字符串变量作为单独的参数发送,我准备了我的Web方法以期待一个aditional string parameter。

该参数在.aspx页面上的javascript函数中 window.location (页面的整个网址)

一旦我的网络服务中有网址,剩下的就是非常直接的

Uri myRef = new Uri(stringMyWindowLocationParameter);
System.Collections.Specialized.NameValueCollection mojQuery = HttpUtility.ParseQueryString(myRef.Query);

现在我的查询字符串包含在 myRef 对象中,这就是我称之为的方式

// Instead trying to request query string like this
string myId = HttpContext.Current.Request.QueryString["id"];

// ... I called it like this
string myId = myRef["id"];

也许这不是最优雅的方式,但它解决了我的问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top