HttpContext.Current.Request.QueryString [英] HttpContext.Current.Request.QueryString
问题描述
嗨
如果我有一个网址/查询,例如localhost?a& b& c = 123那么我以为我可以通过使用
获得这些参数和值来获取这些参数和值.BordValueCollection query = HttpContext.Current.Request.QueryString;
但是,如果我然后尝试query.AllKeys我只得到两个键,即null
和c。
这是正确的行为吗?是a和b被认为是
a null键的值 - 我如何从集合中获取它们?
谢谢,
彼得
Hi
if I have a url/query like "localhost?a&b&c=123" then I thought I could
get these parameters and values by using
NameValueCollection query = HttpContext.Current.Request.QueryString;
But if I then try "query.AllKeys" I only get two keys, namely "null"
and "c".
Is this correct behaviour? Are "a" and "b" considered to be values for
a null key - and how do I get them from the collection?
Thanks,
Peter
推荐答案
Peter写道:
Peter wrote:
嗨
如果我有一个网址/查询,如localhost?a& b& c = 123那么我以为我可以通过使用
获得这些参数和值来获取这些参数和值.BordValueCollection query = HttpContext.Current.Request.QueryString;
但是,如果我然后尝试query.AllKeys我只得到两个键,即null
和c。
这是正确的行为吗?是a和b被认为是
的值是一个空键 - 我如何从集合中获取它们?
Hi
if I have a url/query like "localhost?a&b&c=123" then I thought I could
get these parameters and values by using
NameValueCollection query = HttpContext.Current.Request.QueryString;
But if I then try "query.AllKeys" I only get two keys, namely "null"
and "c".
Is this correct behaviour? Are "a" and "b" considered to be values for
a null key - and how do I get them from the collection?
不应该是查询字符串:localhost?a =& b =& c = 123" ?
FB
-
-------------- -------------------------------------------------- --------
LLBLGen Pro的首席开发人员,.NET的高效O / R映射器
LLBLGen Pro网站: http://www.llblgen.com
我的.NET博客: http://weblogs.asp.net/fbouma
Microsoft MVP(C# )
----------------------------------------- -------------------------------
Shouldn''t the query string be: "localhost?a=&b=&c=123" ?
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Frans Bouma [C# MVP]写道:
Frans Bouma [C# MVP] wrote:
如果我有一个网址/查询,例如localhost?a& b& c = 123那么我以为我可以通过使用
来获取这些参数和值.BordValueCollection query = HttpContext.Current.Request.QueryString;
但是,如果我然后尝试query.AllKeys我只得到两个键,即null
和c。
这是正确的行为吗?是a和b被认为是null值的价值
- 我如何从集合中获取它们?
if I have a url/query like "localhost?a&b&c=123" then I thought I
could get these parameters and values by using
NameValueCollection query = HttpContext.Current.Request.QueryString;
But if I then try "query.AllKeys" I only get two keys, namely "null"
and "c".
Is this correct behaviour? Are "a" and "b" considered to be values
for a null key - and how do I get them from the collection?
难道查询字符串不应该是:localhost?a =& b =& c = 123" ?
Shouldn''t the query string be: "localhost?a=&b=&c=123" ?
是的,我认为你是对的,查询真的应该是这样的。
我想我应该忽略我从AllKeys获得的任何空键(我能用什么来支付
无论如何都使用空键?)
谢谢,
Peter
Yes, I think you''re right, the query should really look like that.
I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)
Thanks,
Peter
4月25日,5:35 * am,Peter < xdz ... @ hotmail.comwrote:
On Apr 25, 5:35*am, "Peter" <xdz...@hotmail.comwrote:
Frans Bouma [C#MVP]写道:
Frans Bouma [C# MVP] wrote:
如果我有一个网址/查询,例如localhost?a& b& c = 123那么我以为我可以通过使用
来获取这些参数和值.BordValueCollection query = HttpContext.Current.Request.QueryString;
if I have a url/query like "localhost?a&b&c=123" then I thought I
could get these parameters and values by using
NameValueCollection query = HttpContext.Current.Request.QueryString;
但是如果我然后尝试query.AllKeys我只得到两个键,即null
和c。
But if I then try "query.AllKeys" I only get two keys, namely "null"
and "c".
这是正确的行为吗?是a和b被认为是null值的价值
- 我如何从集合中获取它们?
Is this correct behaviour? Are "a" and "b" considered to be values
for a null key - and how do I get them from the collection?
* *不应该是查询字符串:localhost?a =& b =& c = 123 ; ?
* *Shouldn''t the query string be: "localhost?a=&b=&c=123" ?
是的,我认为你是对的,查询应该真的像那样。
我想我应该忽略我从AllKeys获得的任何空键(我能用什么来支付
无论如何都使用空键?)
谢谢,
Peter
Yes, I think you''re right, the query should really look like that.
I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)
Thanks,
Peter
谁在生成查询字符串?
正如Frans所说,这是错误的。
你应该为你的所有参数设置默认值,然后只需要
更新QS中值的那些。
所以你最需要做的就是添加if(key == null)继续;
Who is generating that query string?
As Frans mentioned it''s wrong.
You should have default values for all your parameters, and then just
update those with values in the QS.
so all you have to do at the most is adding a if (key==null) continue;
这篇关于HttpContext.Current.Request.QueryString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!