国产探花免费观看_亚洲丰满少妇自慰呻吟_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內容。
(轉)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 二连浩特市| 武强县| 平武县| 鞍山市| 永寿县| 盐池县| 铜川市| 岫岩| 资兴市| 闻喜县| 井冈山市| 博客| 鄄城县| 铜梁县| 德格县| 称多县| 广河县| 商南县| 邛崃市| 溧阳市| 辉南县| 积石山| 巴马| 灵山县| 新野县| 鄂伦春自治旗| 无为县| 温泉县| 保德县| 永康市| 娱乐| 霍州市| 米脂县| 资溪县| 临沧市| 河西区| 雅安市| 宜州市| 黄大仙区| 汾西县| 西乌珠穆沁旗|