ASP.NET查询字符串没有等号 [英] ASP.NET QueryString without equals sign
问题描述
当我有一个像网址:
http://www.mysite.com/?MyTest=
MyTest的显示为在请求对象的查询字符串的关键。
MyTest shows up as a key in the querystring of the request object.
如果我删除=符号,如:
If I remove the = sign like:
它不再查询字符串键显示(或AllKeys如果preFER)。
It no longer shows up in the querystring keys (or AllKeys if you prefer).
如何判断这个键是否存在?
How can I determine whether this key exists or not?
推荐答案
这是很奇怪的行为,没有等号(=)的请求返回的查询字符串对象的1 MyTest的值和空的关键计数。结果
你可以测试查询字符串,看它是否包含您所期望的值:
This is quite odd behaviour, without the = sign the QueryString object returned by the Request has a Count of 1 with a value of MyTest and a key of null.
You could test the QueryString to see if it contains the value you are expecting:
if(Request.QueryString.ToString().Contains("MyTest"))
{
// Do stuff
}
编辑:这个回答给出进一步的解释,什么是无钥匙参数回事(滚过接受的答案)。
this answer gives a bit more explanation as to what is going on with keyless parameters (scroll past the accepted answer).
这篇关于ASP.NET查询字符串没有等号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!