惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
S
Secure Thoughts
博客园 - 三生石上(FineUI控件)
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
H
Help Net Security
博客园 - 叶小钗
爱范儿
爱范儿
GbyAI
GbyAI
I
Intezer
M
MIT News - Artificial intelligence
Latest news
Latest news
Schneier on Security
Schneier on Security
T
Tor Project blog
Simon Willison's Weblog
Simon Willison's Weblog
I
InfoQ
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
N
News and Events Feed by Topic
T
The Blog of Author Tim Ferriss
V2EX - 技术
V2EX - 技术
B
Blog
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
Security Latest
Security Latest
V
V2EX
F
Fortinet All Blogs
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Hacker News
The Hacker News
Scott Helme
Scott Helme
P
Privacy International News Feed
P
Palo Alto Networks Blog
H
Heimdal Security Blog
C
Cisco Blogs
T
The Exploit Database - CXSecurity.com
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
W
WeLiveSecurity
L
LINUX DO - 最新话题

博客园 - changchang

SQL中的join用法(zt) 远程桌面 Web 连接 RTM、RC、CTP版本的含义(ZT) Culture Name(转) - changchang - 博客园 MPEG、RM、WMV电影文件格式转换指南(转) PDF文件相关下载 Form验证(转) .net下枚举的用法 - changchang - 博客园 .net操作文件的基本方法总结 - changchang - 博客园 JavaScript动态的为元素添加事件 (转载)一个大家不常用到,却很有用的页面间传值方法(Context.Handler) - changchang - 博客园 CuteEditor学习总结技巧 Javascript图片幻灯片的实现 Window下配置SVN服务器与客户端 Javascript访问html页面的控件 深入理解.net的事件与委托机制 asp.net控件本质 google map简单实现 asp.net 2.0发送和接收邮件总结
dotnet下Request对象获取客户端数据的方式比较(Request.Params) - changchang - 博客园
changchang · 2007-11-22 · via 博客园 - changchang
   

.net下的Request对象的一个作用就是获取客户端提交的数据,大家对它也是非常熟悉的。虽然如此,但有几种写法的不同可能未必人人都能理解的。
strMessage = Request("msg")
strMessage = Request.Form("msg")
而且好多人写的代码,一律都是Request("")的写法,当然这样的写法并没有什么错。
而不管对于哪种集合其实都是可以通过Request("")这样直接取得的,这里就有一个问题,如果Get方式和Post方式提交了同样的一个变量,比如username=sunny,那么你用Request("username")取出来的到底是Get过来的数据还是Post过来的数据呢?只是大家应该注意Request对象有几个集合来获取客户端提交的数据,一般常用的是QueryString,FormServerVariables
下面我举个例子来说明这个问题:
首先建立一个html页面:index.html

<html>   
<head>
<title></title>
</head>
<body>   
<p>请填写你的优点</p>   
<form method="POST" action="Search.aspx?hobby=0000">   
<p>
<input type="text" name="hobby" size="20"><br>   
<input type="checkbox" name="hobby" value=" 正义">正义<input type="checkbox" name="hobby" value=" 老实 ">老实
</p>   
<p><input type="submit" value=" 确定 " name="B1"><input type="reset" value=" 重填 " name="B2">
</p>   
</form> 
</body></html>

建立新的页面Search.aspx,页面什么都不需要,这里只是说明个问题就是得,后台代码如下:

Code

 我在index.html页面上输入了"长得帅",又在下面的两个checkbox都选择了,单击按钮提交数据到Search.aspx页面
Str1=“长得帅,正义,老实”
Str2="0000";
Str3=”0000,长的帅,正义,老实
Str4="";
tr5=”0000”;

所以,问题到了这里,大家就应该想到了, Request从这几个集合取数据是有顺序的,从前到后的顺序依次是 QueryString,Form,最后是ServerVariables。

Request.Form实际上是获取由form方式提交的数据
Request.QueryString实际上是获取由get方式提交的数据。
Request.Params则是由几部分组成:获取QueryString+Form+ServerVariable+Cookies的集合.所以上面的例

子str3=request[“hobby”]取到的就是有这几个组成的集合。
Request.Servervariables则是获取客户端相关的信息,如IE类型,IP地址等等。
Request对象按照这样的顺序依次搜索这几个集合中的变量,如果有符合的就中止,后面的就不管了。所以
上面的例子str5=Request["hobby"]取到的实际是Get方法提交的数据。

所以为了提高效率,减少无谓的搜索时间,同时也是为了程序的规范,建议大家还是用Request.集合的方

式更好一点,比如Request.Form("hobby")。