国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

從Web Services中訪問服務器變量

2024-07-21 02:21:29
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

在新聞組中最經常被問到的問題就是“如何從一個web services(web服務)內部獲取客戶瀏覽器的ip地址?” 這個問題的答案非常簡單。system.web.services名稱空間內部的context類代表了web服務的上下文。換句話說,它從一個正在運行的web服務內部對不同的對象進行引用。比如response(響應)、request(請求)和session對象,以及在服務上調試是否激活之類的信息。

本文我們用一個非常基本的例子來描述兩件事:

1、取得客戶瀏覽器的ip地址
2、取得所有的web 服務器變量

源代碼如下,很容易理解:

<%@ webservice language="c#" class="httpvars" %>
using system;
using system.collections;
using system.web.services;
public class httpvars : webservice
{
// this method returns the ip address of the client
[webmethod]
public string ipaddress ()
{
// the context object contains reference to request object
return context.request.servervariables["remote_addr"];
}
// this method returns the all the server variables as html
[webmethod]
public string allhttpvars ()
{
// instantiate a collection that will hold the
// key-value collection of server variables
namevaluecollection servervars;
string returnvalue = "";
servervars = context.request.servervariables;
// retrieve all the keys from server variables collection
// as a string array
string[] arvars = servervars.allkeys;
// loop through the keys array and obtain the
// values corresponding to the individual keys
for (int x = 0; x < arvars.length; x++)
{
returnvalue+= "<b>" + arvars[x] + "</b>: ";
returnvalue+= servervars[arvars[x]] + "<br>";
}
return returnvalue;
}
}

http://www.dotnet101.com/articles/demo/art033_servervars.asmx進行代碼演示。注意:第二個方法allhttpvars()返回html內容。
(轉)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安化县| 栖霞市| 外汇| 康平县| 临沂市| 甘南县| 东辽县| 鄂尔多斯市| 江达县| 巴林左旗| 蒙自县| 罗城| 虎林市| 开化县| 鄢陵县| 红安县| 天水市| 历史| 定远县| 太谷县| 台北市| 浮山县| 新野县| 武鸣县| 景宁| 邵阳县| 尉氏县| 德昌县| 墨脱县| 云阳县| 金昌市| 佛冈县| 扶沟县| 桂阳县| 兴业县| 昆明市| 琼中| 南投县| 鞍山市| 曲周县| 合肥市|