2015-11-20 81 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 
%>