![](/img/trans.png)
[英]How to obtain a parameter value from a URL to a web form in asp.net?
[英]ASP.NET webservice: Obtain value from URL for operation
我看過網絡,但似乎無法找到一個體面的例子。
在php中我們可以使用GET從URL中提取變量; 怎么在asmx中完成?
[WebMethod(Description = "multiply two numbers")]
public int mul(int num1, int num2)
{
//num1 = Request.QueryString["num1"];
//num2 = Request.QueryString["num2"];
return num1 * num2;
}
我已將以下內容插入到web.config文件中以啟用GET:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
說的網址是http://www.yoursite.com/default.aspx?stuff=2
得到的東西作為參數代碼
string stuff=Request.Params["stuff"];
請注意,該值存儲為字符串。
我不確定你如何調用asmx客戶端,但是在web方法上你可能需要添加明確指定“GET”的ScriptMethod。
[WebMethod(Description = "multiply two numbers")]
[ScriptMethod(UseHttpGet = true)]
public int mul(int num1, int num2)
{
return num1 * num2;
}
Server.Transfer("admin.aspx?SelectedView=view1", true);
您可以使用上面的代碼獲取傳遞的變量。
String selectedView = Request.QueryString["SelectedView"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.