简体   繁体   English

VB.NET 查询字符串有参数

[英]VB.NET querystring has parameter

How do I check if a query string has a parameter in VB.NET?如何检查查询字符串在 VB.NET 中是否有参数? I'm having a hard time adapting C# code to VB.我很难让 C# 代码适应 VB。

I'm particularly interested in determining if a value-less/key-less parameter exists.我对确定是否存在无值/无键参数特别感兴趣。

Pseudo-Code:伪代码:

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

Examples:例子:

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

To clarify, I don't care whether or not test has a value.澄清一下,我不在乎test是否有价值。 I just want to know if it is in the query string or not.我只想知道它是否在查询字符串中。

You were close.你很接近。 Use:用:

If Request.QueryString.ToString.Contains("test") Then
    ' ...
End If
if Request.QueryString("test").Count > 0  then
    ...
end if

Source: https://www.w3schools.com/asp/coll_querystring.asp来源: https : //www.w3schools.com/asp/coll_querystring.asp

This should address both scenarios:这应该解决这两种情况:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM