if (Request.QueryString.HasKeys() && Request.QueryString.GetKey(0) == "aspxerrorpath")
{
//It has a key and the key is valid
string KeyValueByIndex = Request.QueryString[0];
//OR
string KeyValueByName = Request.QueryString["aspxerrorpath"];
}
else
{
//else...
}
9条答案
按热度按时间bhmjp9jg1#
您可以查看
null
:字符串
vfh0ocws2#
检查参数的值:
字符串
如果它不存在,值将是
null
,如果它存在,但没有设置值,它将是一个空字符串。我相信上面的代码比
null
的测试更适合您的需要,因为空字符串对于您的特定情况同样糟糕。r7xajy2e3#
要检查空QueryString,您应该使用
Request.QueryString.HasKeys
属性。检查密钥是否存在:
Request.QueryString.AllKeys.Contains()
个然后你可以获取ist的Value并做任何你想要的检查,比如isNullOrEmpty等等。
idv4meu84#
您也可以尝试:
字符串
czfnxgou5#
字符串
如果有值,将返回
du7egjpx6#
不如直接一点?
字符串
qpgpyjmq7#
我想你要的支票是这个
字符串
它返回
null
,因为在该查询字符串中,该键没有值。23c0lvtd8#
要解决问题,请在页面的Page_Load方法上写入以下行。
字符串
.Net 4.0提供了对null、empty或whitespace字符串的更深入的了解,请按以下行所示使用它:
型
如果查询字符串没有aspxerrorpath,这将不会运行您的下一个语句(您的业务逻辑)。
oxf4rvwz9#
//使用Haskeys()和GetKey(0)
字符串