在ASP.NET中有一个很重要的Property叫做HttpRequest.ServerVariables,通过这个Property可以取出很多用户浏览器的信息,例如IP地址等等。

例如取出IP地址信息。

trueIP = Request.ServerVariables["REMOTE_ADDR"];

到底能取出那些信息,和IIS服务器有关,详细可以参考IIS Server Variables

Variable

Description

ALL_HTTP

All HTTP headers sent by the client.

ALL_RAW

Retrieves all headers in raw form. The difference between ALL_RAW and ALL_HTTP is that ALL_HTTP places an HTTP_ prefix before the header name and the header name is always capitalized. In ALL_RAW the header name and values appear as they are sent by the client.

APP_POOL_ID

IIS 5.1 and earlier: This server variable is not available.

Returns the name of the application pool that is running in the IIS worker process that is handling the request.

There is also an APP_POOL_ID environment variable that is available to applications that are running in the IIS worker process.

APPL_MD_PATH

Retrieves the metabase path of the application.

APPL_PHYSICAL_PATH

Retrieves the physical path corresponding to the metabase path in APPL_MD_PATH.

AUTH_PASSWORD

The value entered in the client's authentication dialog. This variable is available only if Basic authentication is used.

AUTH_TYPE

The authentication method that the server uses to validate users when they attempt to access a protected script.

It does not mean that the user was authenticated if AUTH_TYPE contains a value and the authentication scheme is not Basic or integrated Windows authentication. The server allows authentication schemes it does not natively support because an ISAPI filter may be able to handle that particular scheme.

AUTH_USER

The name of the user as it is derived from the authorization header sent by the client, before the user name is mapped to a Windows account. This variable is no different from REMOTE_USER. If you have an authentication filter installed on your Web server that maps incoming users to accounts, use LOGON_USER to view the mapped user name.

CACHE_URL

IIS 5.1 and earlier: This server variable is not available.

For use in ISAPI applications only. Returns the unambiguous name for the current URL. It is necessary to use the Unicode version of this variable in conjunction with the kernel mode cache invalidation function to evict entries placed in the cache by HSE_REQ_VECTOR_SEND.

Note:

The server variable "UNICODE_CACHE_URL" is used in conjunction with the cache invalidation function retrieved by the HSE_REQ_GET_CACHE_INVALIDATION_CALLBACK function. This function invalidates responses cached in HTTP.SYS, whether those responses are produced by requests or by ISAPIs calling HSE_REQ_VECTOR_SEND.

CERT_COOKIE

Unique ID for the client certificate, returned as a string. This can be used as a signature for the whole client certificate.

CERT_FLAGS

bit0 is set to 1 if the client certificate is present.

bit1 is set to 1 if the certification authority of the client certificate is invalid (that is, it is not in the list of recognized certification authorities on the server).

If bit 1 of CERT_FLAGS is set to 1, indicating that the certificate is invalid, IIS version 4.0 and later will reject the certificate. Earlier versions of IIS will not reject the certificate.

CERT_ISSUER

Issuer field of the client certificate (O=MS, OU=IAS, CN=user name, C=USA).

CERT_KEYSIZE

Number of bits in the Secure Sockets Layer (SSL) connection key size. For example, 128.

CERT_SECRETKEYSIZE

Number of bits in server certificate private key. For example, 1024.

CERT_SERIALNUMBER

Serial number field of the client certificate.

CERT_SERVER_ISSUER

Issuer field of the server certificate.

CERT_SERVER_SUBJECT

Subject field of the server certificate.

CERT_SUBJECT

Subject field of the client certificate.

CONTENT_LENGTH

The length of the content as given by the client.

CONTENT_TYPE

The data type of the content. Used with queries that have attached information, such as the HTTP queries GETPOST, and PUT.

GATEWAY_INTERFACE

The revision of the CGI specification used by the server. The format is CGI/revision.

HEADER_<HeaderName>

IIS 5.1 and earlier: This server variable is not available.

The value stored in the header <HeaderName>. Any header other than those listed in this table must be preceded by "HEADER_" in order for the ServerVariables collection to retrieve its value. This is useful for retrieving custom headers.

Note:

Unlike HTTP_<HeaderName>, all characters in HEADER_<HeaderName> are interpreted as-is. For example, if you specify HEADER_MY_HEADER, the server searches for a request header named MY_HEADER.

HTTP_<HeaderName>

The value stored in the header <HeaderName>. Any header other than those listed in this table must be preceded by "HTTP_" in order for the ServerVariables collection to retrieve its value. This is useful for retrieving custom headers.

Note:

The server interprets any underscore (_) characters in <HeaderName> as dashes in the actual header. For example, if you specify HTTP_MY_HEADER, the server searches for a request header named MY-HEADER.

HTTP_ACCEPT

Returns the value of the Accept header that contains a list of accepted formats, for example, "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel".

The values of the fields for the HTTP_ACCEPT variable are concatenated, and separated by a comma (,).

HTTP_ACCEPT_ENCODING

Returns a list of accepted encoding types, for example, "gzip, deflate".

HTTP_ACCEPT_LANGUAGE

Returns a string describing the language to use for displaying content.

HTTP_CONNECTION

Returns a string describing the connection type, for example, "Keep-Alive".

HTTP_COOKIE

Returns the cookie string that was included with the request.

HTTP_HOST

Returns the name of the Web server. This may or may not be the same as SERVER_NAME depending on type of name resolution you are using on your Web server (IP address, host header).

HTTP_METHOD

The method used to make the request (same as REQUEST_METHOD).

HTTP_REFERER

Returns a string that contains the URL of the page that referred the request to the current page using an HTML <A> tag. Note that the URL is the one that the user typed into the browser address bar, which may not include the name of a default document.

If the page is redirected, HTTP_REFERER is empty.

HTTP_REFERER is not a mandatory member of the HTTP specification.

HTTP_URL

Returns the raw, encoded URL, for example, "/vdir/default.asp?querystring".

HTTP_USER_AGENT

Returns a string describing the browser that sent the request.

HTTP_VERSION

The name and version of the request protocol (the raw form of SERVER_PROTOCOL).

HTTPS

Returns ON if the request came in through a secure channel (for example, SSL); or it returns OFF, if the request is for an insecure channel.

HTTPS_KEYSIZE

Number of bits in the SSL connection key size. For example, 128.

HTTPS_SECRETKEYSIZE

Number of bits in the server certificate private key. For example, 1024.

HTTPS_SERVER_ISSUER

Issuer field of the server certificate.

HTTPS_SERVER_SUBJECT

Subject field of the server certificate.

INSTANCE_ID

The ID for the IIS instance in textual format. If the instance ID is 1, it appears as a string. You can use this variable to retrieve the ID of the Web server instance (in the metabase) to which the request belongs.

INSTANCE_META_PATH

The metabase path for the instance of IIS that responds to the request.

LOCAL_ADDR

Returns the server address on which the request came in. This is important on computers where there can be multiple IP addresses bound to the computer, and you want to find out which address the request used.

LOGON_USER

The Windows account that the user is impersonating while connected to your Web server. Use REMOTE_USER, UNMAPPED_REMOTE_USER, or AUTH_USER to view the raw user name that is contained in the request header. The only time LOGON_USER holds a different value than these other variables is if you have an authentication filter installed.

PATH_INFO

Path information, as given by the client, for example, "/vdir/myisapi.dll/zip". If this information comes from a URL, it is decoded by the server before it is passed to the CGI script or ISAPI filter.

If the AllowPathInfoForScriptMappings metabase property is set to true (to support exclusive CGI functionality), PATH_INFO will only contain "/zip" and ISAPI applications such as ASP will break.

PATH_TRANSLATED

The physical path that maps to the virtual path in PATH_INFO, for example, "c:\inetpub\wwwroot\vdir\myisapi.dll". This variable is used by IIS during the processing of ISAPI applications.

If the AllowPathInfoForScriptMappings metabase property is set to true (to support exclusive CGI functionality), PATH_INFO will only contain "/zip" and ISAPI applications such as ASP will break.

QUERY_STRING

Query information stored in the string following the question mark (?) in the HTTP request.

REMOTE_ADDR

The IP address of the remote host that is making the request.

REMOTE_HOST

The name of the host that is making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.

REMOTE_PORT

The client port number of the TCP connection.

REMOTE_USER

The name of the user as it is derived from the authorization header sent by the client, before the user name is mapped to a Windows account. If you have an authentication filter installed on your Web server that maps incoming users to accounts, use LOGON_USER to view the mapped user name.

REQUEST_METHOD

The method used to make the request. For HTTP, this can be GETHEADPOST, and so on.

SCRIPT_NAME

A virtual path to the script being executed, for example, "/vdir/default.asp". This is used for self-referencing URLs.

SCRIPT_TRANSLATED

IIS 5.1 and earlier: This server variable is not available.

The canonical physical path to the script listed in SCRIPT_NAME, for example, "\\?\c:\inetpub\wwwroot\vdir\default.asp".

SERVER_NAME

The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.

SERVER_PORT

The server port number to which the request was sent.

SERVER_PORT_SECURE

A string that contains either 0 or 1. If the request is being handled on the secure port, then this is 1. Otherwise, it is 0.

SERVER_PROTOCOL

The name and revision of the request information protocol. The format is protocol/revision. (The canonicalized form of HTTP_VERSION.)

SERVER_SOFTWARE

The name and version of the server software that answers the request and runs the gateway. The format is name/version.

SSI_EXEC_DISABLED

IIS 5.1 and earlier: This server variable is not available.

Returns a 1 if the server-side include directive, #exec, is disabled. Otherwise, SSI_EXE_DISABLED returns a 0. To enable or disable #exec, use the SSIExecDisablemetabase property.

UNENCODED_URL

IIS 4.0 and earlier: This server variable is not available.

Returns the raw, unencoded URL, for example, "/vdir/default.asp?querystring".

UNICODE_<ServerVariable Name>

IIS 5.1 and earlier: This server variable is not available.

In unicode ISAPI applications only, it is possible to retrieve server variable values as unicode values by prepending "UNICODE_" to the name of the server variable, unless the variable starts with "HTTP_" or "HEADER_".

UNMAPPED_REMOTE_USER

The name of the user as it is derived from the authorization header sent by the client, before the user name is mapped to a Windows account (same as REMOTE_USER). If you have an authentication filter installed on your Web server that maps incoming users to accounts, use LOGON_USER to view the mapped user name.

URL

Gives the base portion of the URL, without any querystring or extra path information, for example, "/vdir/default.asp".

For the raw URL, use HTTP_URL or UNENCODED_URL.

URL_PATH_INFO

Note: This server variable is only available on IIS 5.0.

Use PATH_INFO instead.

关于取客户端的IP地址,有时候使用REMOTE_ADDR是不够的,例如客户端经过ADSL拨号访问Internet,那么可以借助HTTP_X_FORWARDED_FOR来取出经过proxy转换的地址。

如果经过proxy转换,HTTP_X_FORWARDED_FOR取出来是逗号分开的一串地址,取出第一个是客户端的IP地址。

本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2010/04/16/ASP-Dot-NET-Retrieve-Browser-IP.html,如需转载请自行联系原作者

ASP.NET取用户浏览器IP地址等信息相关推荐

  1. linux shell 域名 ip,Shell脚本一种检查Linux中域名和IP地址所有权信息、检查多个域名的到期日期工具...

    Shell脚本一种检查Linux中域名和IP地址所有权信息.检查多个域名的到期日期工具 jwhois是一个命令行实用程序,可从whois服务器(whois数据库)中获取有关域名所有权的信息. Whoi ...

  2. 5 获取当前访问的控制名称_LabVIEW编程技巧:网络通信中如何获取计算机名称、IP地址等信息...

    问题引出 在网络通讯编程中,经常需要获取当前主机的名称.IP地址等信息,在LabVIEW中如何获取这些信息呢? 下面以本机为例进行说明,先看一下本机的信息.在Windows系统中打开控制台程序,输入& ...

  3. 在桌面上显示IP地址等信息

    看到以上的图大家感觉不错吧,至少给经常需要网络管理的朋友提供了方便.如何实现在桌面正常显示IP地址等信息呢? 其实这个功能是用BGInfo实现的.它是微软免费提供的小工具,支持命令行. 以下是微软英文 ...

  4. 使用Python批量查询ip地址的信息

    使用Python批量查询ip地址的信息 import requests from openpyxl import load_workbook from bs4 import BeautifulSoup ...

  5. Kali配置静态IP地址等信息

    文章目录 前言 一.Kali配置IP地址等信息(命令行配置) 1.停止网卡服务 2.进入配置文件 3.设置IP地址.DNS服务器等信息 4.启动网卡服务 二.Kali配置IP地址等信息(控制面板中设置 ...

  6. ASP如何获取客户端真实IP地址

    在ASP中使用 Request.ServerVariables("REMOTE_ADDR") 来取得客户端的IP地址, 但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 ...

  7. asp.net获取URL和IP地址(转)

    HttpContext.Current.Request.Url.ToString() 并不可靠. 如果当前URL为  http://localhost/search.aspx?user=http:// ...

  8. asp.net获取URL和IP地址

    HttpContext.Current.Request.Url.ToString() 并不可靠. 如果当前URL为  http://localhost/search.aspx?user=http:// ...

  9. 【ASP.NET 进阶】根据IP地址进行百度地图定位

    昨天有完成一个[ASP.NET 进阶]根据IP返回对应位置信息 的小Demo,既然可以通过IP获得位置信息,那当然可以通过位置信息的经纬度获取IP的当前定位了,虽然与实际地址偏移较大,毕竟不是GPRS ...

最新文章

  1. re.split()用法详解
  2. 全球十大AI训练芯片大盘点:华为昇腾910是中国唯一入选
  3. python各个解释器的用途-【Python面试】 说说Python解释器种类以及特点?
  4. 几种常见的Web攻击
  5. matlab车流量检测,求解释代码,一段交通车流量检测的代码
  6. LeetCode刷题——70. 爬楼梯
  7. 关于3Q大战和反垄断
  8. 基于CANape开发的XCP测量
  9. interview-db
  10. 微信 表情 android,android - 微信自定义表情在哪个文件夹?
  11. 京东优惠价格策略助手
  12. 网页制作:制作一个官网
  13. 洛谷P3435 [POI2006]OKR-Periods of Words题解(KMP)
  14. 降维中信息的损失对聚类结果的影响图形化表示
  15. 银联商务管理层换血:光大控股后撤,曾因违规被罚没3267万元
  16. 美国B1/B2签证免面试续签流程 2016年5月份更新
  17. 企业文化在企业管理中的作用
  18. 小学生学习Python的步骤和学习周期之我见
  19. 【折腾日记GEN8_2】ESXI的安装
  20. Android 8源码目录结构详解

热门文章

  1. 为什么不用php做系统吗,IT行业:为什么大部分人都不认可php语言呢?
  2. jQuery的创建对象,动态添加、修改、删除属性和方法
  3. python输出99乘法表_如何用python输出99乘法表
  4. python的三种数据类型列举_3.Python编程之数据类型
  5. 解决log4j.properties不起作用的问题
  6. vb读取文件的模式和方法
  7. ubuntu 重装系统备份数据 ubuntu安装kde桌面
  8. 视频直接变漫画!GAN又有了新玩法 | Demo+代码+论文
  9. 飞步神速!何晓飞团队完成无人车深度学习芯片流片,算力创国内新高
  10. 华盛顿大学成立SAML实验室:陈天奇参与,推进未来AI系统全栈研究