ASP.NET-细节-Request.QueryString和R
本文主要解释Request.QueryString和Request.Form、Request.Cookies、Request.ServerVariables传值
取值
若是要在两个页面传递数据的话,只能用request.querystring、request.form、request.cookies,对于在这三个参数里面的内容可以通过Request.querystring("key名称")、Request.form("key名称")、Request.cookies("key名称")、Request.ServerVariables("key名称")来进行获取;
当然有种不推荐的方式是request("key名称"),这种是不太好的,因为Request从几个集合取数据是有顺序的,从前到后的顺序依次是 QueryString,Form,最后是ServerVariables。Request对象按照这样的顺序依次搜索这几个集合中的变量;
Request.QueryString和Request.Form的比较
Request.QueryString:get方法递交的表单或通过url传值采用request.querystring进行获值的方法
缺点:(1)参数值明码显示(2)长度受限;
优点:(1)方便可以直接定义一个url就可以传值;作用:常用与数据库中的文章id传值,进行数据库的查询;
Request.Form:对于post传值的方法,采用request.form接受
他的参数值不会在url中用明文方式显示,且长度不受限制,安全性相对较高(只是相对url传值来说);
特别的,对于Request.Cookies
Request.Cookies:主要是用于获取所有Cookie值的,包括JS、Request.Cookies和Response.Cookies三种方法创建的Cookie值;
Request.Cookies既可以获取Cookie也可以创建Cookie;
Request.Cookies创建的Cookie与Response和JS创建的Cookie的不同:Request.Cookies创建的Cookie只有?Request.Cookies才能获取到,而其他两种方法是不能获取的,也就是说Request.Cookies创建的Cookie只能用于.Net后台不能用于HTML的前台;
监视实例
request.querystring
request.form
request.cookies
Request.ServerVariables
实例代码
这里是写在全局里面,如果需要的话摘除出去页面后台代码事件里面也可以的
Private Sub Application_BeginRequest(ByVal Sender As Object, ByVal E As EventArgs) Handles Me.BeginRequest
If Request.QueryString.Count > 0 Then
For Each field As String In Request.QueryString
Request.QueryString(field)
/*
代码体
*/
Next
End If
If Request.Form.Count > 0 Then
For Each field As String In Request.Form
Request.Form(field)
/*
代码体
*/
Next
End If
If Request.Cookies.Count > 0 Then
For Each field As String In Request.Cookies
Request.Cookies(field)
/*
代码体
*/
Next
End If
If Request.ServerVariables.Count > 0 Then
For Each field As String In Request.ServerVariables
Request.ServerVariables(field)
/*
代码体
*/
Next
End If
End Sub
最后附上Request.ServerVariables的参数含义
PS:此处的Request.ServerVariables的参数含义总结参考自CSDN博主「sdh_down」的转载文章
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"]
Request.ServerVariables变量意义. http代理相关知识
Request.ServerVariables["HTTP_VIA"]---------可以获得用户内部的ip
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]---------可以知道代理服务器的服务器名以及端口
Request.ServerVariables["REMOTE_ADDR"]-- 发出请求的远程主机的 IP 地址。
http代理相关知识
关键就在HTTP_X_FORWARDED_FOR
使用不同种类代理服务器,上面的信息会有所不同:
一、没有使用代理服务器的情况:
REMOTE_ADDR = 您的 IP
HTTP_VIA = 没数值或不显示
HTTP_X_FORWARDED_FOR = 没数值或不显示
二、使用透明代理服务器的情况:Transparent Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 您的真实 IP
这类代理服务器还是将您的信息转发给您的访问对象,无法达到隐藏真实身份的目的。
三、使用普通匿名代理服务器的情况:Anonymous Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 代理服务器 IP
隐藏了您的真实IP,但是向访问对象透露了您是使用代理服务器访问他们的。
四、使用欺骗性代理服务器的情况:Distorting Proxies
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 代理服务器 IP
HTTP_X_FORWARDED_FOR = 随机的 IP
告诉了访问对象您使用了代理服务器,但编造了一个虚假的随机IP代替您的真实IP欺骗它。
五、使用高匿名代理服务器的情况:High Anonymity Proxies (Elite proxies)
REMOTE_ADDR = 代理服务器 IP
HTTP_VIA = 没数值或不显示
HTTP_X_FORWARDED_FOR = 没数值或不显示