2008-11-18 92 views

回答

17

我只是在asmx文件中查找上下文的「請求」,我看到了。但我不確定是否正確。

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

這代表什麼對象? – AnthonyWJones 2008-11-18 09:28:09

2

既然你問了,我估計沒有HttpContext.Current.Request?

6

HttpContext.Current.Request.QueryString [「ID」]

2

當搜索同樣的問題,我決定採取不同的方法的解決方案。 我的查詢字符串打包了很多變量,因爲我無法從Web服務訪問查詢字符串數據,而且我也不想將每個查詢字符串變量作爲單獨的參數發送,所以我準備了我的Web方法以期望一個附加的字符串參數。

這個參數是在我的javascript函數window.location的(頁面的整個URL).aspx頁面中

一次我在Web服務有網址,其餘是相當挺直向前

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"]; 

也許這不是最優雅的方式,但它解決了我的問題。

相關問題