2015-11-20 82 views
2

如何检查查询字符串在VB.NET中是否有参数?我很难适应C#代码到VB。VB.NET查询字符串有参数

我对确定是否存在无值/无关键参数特别感兴趣。

伪代码:

If Request.QueryString.Contains("test") Then 
    ' ... 
End If 

例子:

http://example.com/mypage.aspx?test 
http://example.com/mypage.aspx?test=1 
http://example.com/mypage.aspx?someparam=1&test&anotherparam=2 

为了澄清,我不在乎test是否具有价值。我只想知道它是否在查询字符串中。

回答

2

您近距离了。用途:

If Request.QueryString.ToString.Contains("test") Then 
    ' ... 
End If 
+0

感谢。这将适用于我的场景,但值得注意的是,如果另一个参数的值在其值中包含相同的'test'字符串,即'?someparam = test',则可能有匹配。 – Quantastical

+1

@Quantastical不应该太复杂。在这种情况下,除了上述解决方案之外,还应该检查键/值对的实际值。 –

0

这应该解决这两个场景:

<%@ Page Language="VB"%> 
<% 
if Request.QueryString("test")<>"" then 
    Response.Write ("EXISTS") 
else 
    Response.Write ("not defined") 
end if 
%>