请求["键"] VS Request.Params ["键"] VS的Request.QueryString ["键"] [英] Request["key"] vs Request.Params["key"] vs Request.QueryString["key"]

查看:273
本文介绍了请求["键"] VS Request.Params ["键"] VS的Request.QueryString ["键"]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求[钥匙] VS Request.Params [钥匙] VS 的Request.QueryString [钥匙]

哪种方法,你经验丰富的程序员使用?为什么?

Which method do you seasoned programmers use? and why?

推荐答案

我建议的Request.QueryString [钥匙] 。没有很大的差异,以请求[钥匙] 的查询字符串但如果你试图从值大(ER)的区别 ServerVariables 请求[钥匙] 会在查询字符串值如果为null,它着眼于表格,那么饼干最后 ServerVariables

I recommend Request.QueryString["key"]. There isn't a lot of difference to Request["Key"] for a query string but there is a big(er) difference if you are trying to get the value from ServerVariables. Request["Key"] looks for a value in QueryString if null, it looks at Form, then Cookie and finally ServerVariables.

使用 PARAMS 是最昂贵的。到PARAMS第一个请求创建一个新的的NameValueCollection 键,把每个查询字符串表单<的/ code>,饼干 ServerVariables 到此集合。对于第二个请求上它比更好的性能要求[钥匙]

Using Params is the most costly. The first request to params creates a new NameValueCollection and adds each of the QueryString, Form, Cookie and ServerVariables to this collection. For the second request on it is more performant than Request["Key"].

说了这么多了几个关键的性能差异是相当微不足道。这里的关键是code应显示意图,并使用的Request.QueryString 讲清楚你的意图是什么。

Having said that the performance difference for a couple of keys is fairly negligable. The key here is code should show intent and using Request.QueryString makes it clear what your intent is.

这篇关于请求[&QUOT;键&QUOT;] VS Request.Params [&QUOT;键&QUOT;] VS的Request.QueryString [&QUOT;键&QUOT;]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆