asp.net Request.ServerVariables[] 讀解

來源:互聯網
上載者:User

擷取用戶端的IP地址,代碼如下:

複製代碼 代碼如下:/// <summary>
/// 擷取用戶端IP地址
/// </summary>
/// <returns></returns>
public string GetClientIP()
{
string userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (userIP == null)
userIP = Request.ServerVariables["REMOTE_ADDR"];
return userIP;
}

名詞解釋: ServerVariables -- 伺服器變數

Request.ServerVariables("Url")
返回伺服器位址
Request.ServerVariables("Path_Info")
用戶端提供的路徑資訊
Request.ServerVariables("Appl_Physical_Path")
與應用程式中繼資料庫路徑相應的實體路徑
Request.ServerVariables("Path_Translated")
通過由虛擬至物理的映射後得到的路徑
Request.ServerVariables("Script_Name")
執行指令碼的名稱
Request.ServerVariables("Query_String")
查詢字串內容
Request.ServerVariables("Http_Referer")
請求的字串內容
Request.ServerVariables("Server_Port")
接受請求的伺服器連接埠號碼
Request.ServerVariables("Remote_Addr")
發出請求的遠程主機的IP地址
Request.ServerVariables("Remote_Host")
發出請求的遠程主機名稱
Request.ServerVariables("Local_Addr")
返回接受請求的伺服器位址
Request.ServerVariables("Http_Host")
返回伺服器位址
Request.ServerVariables("Server_Name")
伺服器的主機名稱、DNS地址或IP地址
Request.ServerVariables("Request_Method")
提出請求的方法比如GET、HEAD、POST等等
Request.ServerVariables("Server_Port_Secure")
如果接受請求的伺服器連接埠為安全連接埠時,則為1,否則為0
Request.ServerVariables("Server_Protocol")
伺服器使用的協議的名稱和版本
Request.ServerVariables("Server_Software")
應答請求並運行網關的伺服器軟體的名稱和版本
Request.ServerVariables("All_Http")
用戶端發送的所有HTTP標題,首碼HTTP_
Request.ServerVariables("All_Raw")
用戶端發送的所有HTTP標題,其結果和用戶端發送時一樣,沒有首碼HTTP_
Request.ServerVariables("Appl_MD_Path")
應用程式的中繼資料庫路徑
Request.ServerVariables("Content_Length")
用戶端發出內容的長度
Request.ServerVariables("Https")
如果請求穿過安全通道(SSL),則返回ON如果請求來自非安全通道,則返回OFF
Request.ServerVariables("Instance_ID")
IIS執行個體的ID號
Request.ServerVariables("Instance_Meta_Path")
響應請求的IIS執行個體的中繼資料庫路徑
Request.ServerVariables("Http_Accept_Encoding")
返回內容如:gzip,deflate
Request.ServerVariables("Http_Accept_Language")
返回內容如:en-us
Request.ServerVariables("Http_Connection")
返回內容:Keep-Alive
Request.ServerVariables("Http_Cookie")
返回內容如:nVisiT%
2DYum=125;ASPSESSIONIDCARTQTRA=FDOBFFABJGOECBBKHKGPFIJI;ASPSESSIONIDCAQQTSRB=LKJJPLABABILLPCOGJGAMKAM;ASPSESSIONIDACRRSSRA=DK
HHHFBBJOJCCONPPHLKGHPB
Request.ServerVariables("Http_User_Agent")
返回內容:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)
Request.ServerVariables("Https_Keysize")
安全通訊端層串連關鍵字的位元,如128
Request.ServerVariables("Https_Secretkeysize")
伺服器驗證私人關鍵字的位元如1024
Request.ServerVariables("Https_Server_Issuer")
伺服器憑證的發行者欄位
Request.ServerVariables("Https_Server_Subject")
伺服器憑證的主題欄位
Request.ServerVariables("Auth_Password")
當使用基本驗證模式時,客戶在密碼對話方塊中輸入的密碼
Request.ServerVariables("Auth_Type")
是使用者訪問受保護的指令碼時,伺服器用於檢驗使用者的驗證方法
Request.ServerVariables("Auth_User")
代證的使用者名稱
Request.ServerVariables("Cert_Cookie")
唯一的客戶認證ID號
Request.ServerVariables("Cert_Flag")
客戶認證標誌,如有用戶端認證,則bit0為0如果用戶端認證驗證無效,bit1被設定為1
Request.ServerVariables("Cert_Issuer")
使用者認證中的發行者欄位
Request.ServerVariables("Cert_Keysize")
安全通訊端層串連關鍵字的位元,如128
Request.ServerVariables("Cert_Secretkeysize")
伺服器驗證私人關鍵字的位元如1024
Request.ServerVariables("Cert_Serialnumber")
客戶認證的序號欄位
Request.ServerVariables("Cert_Server_Issuer")
伺服器憑證的發行者欄位
Request.ServerVariables("Cert_Server_Subject")
伺服器憑證的主題欄位
Request.ServerVariables("Cert_Subject")
用戶端認證的主題欄位
Request.ServerVariables("Content_Type")
客戶發送的form內容或HTTPPUT的資料類型
Request.ServerVariables("HTTP_X_FORWARDED_FOR")
可以獲得位於代理(網關)後面的直接IP,當然必須這個代理支援
一些被隱藏起來的Request.ServerVariables參數:
Request.ServerVariables("NUMBER_OF_PROCESSORS")
Request.ServerVariables("OS")
Request.ServerVariables("WINDIR")
Request.ServerVariables("TEMP")
Request.ServerVariables("TMP")
Request.ServerVariables("ComSpec")
Request.ServerVariables("Os2LibPath")
Request.ServerVariables("Path")
Request.ServerVariables("PATHEXT")
Request.ServerVariables("PROCESSOR_ARCHITECTURE")
Request.ServerVariables("PROCESSOR_IDENTIFIER")
Request.ServerVariables("PROCESSOR_LEVEL")
Request.ServerVariables("PROCESSOR_REVISION")
本機ip:<%=request.servervariables("remote_addr")%>
伺服器名:<%=Request.ServerVariables("SERVER_NAME")%>
伺服器IP:<%=Request.ServerVariables("LOCAL_ADDR")%>
伺服器連接埠:<%=Request.ServerVariables("SERVER_PORT")%>
伺服器時間:<%=now%>
IIS版本:<%=Request.ServerVariables("SERVER_SOFTWARE")%>
指令碼逾時時間:<%=Server.ScriptTimeout%>
本檔案路徑:<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%>
伺服器CPU數量:<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%>
伺服器解譯引擎:<%=ScriptEngine & "/"& ScriptEngineMajorVersion&"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
伺服器作業系統:<%=Request.ServerVariables("OS")%>
支援的檔案類型:<%=Request.ServerVariables("HTTP_Accept")%>
訪問的檔案路徑:<%=Request.ServerVariables("HTTP_url")%>
使用者代理程式的資訊:<%=Request.ServerVariables("HTTP_USER_AGENT")%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.