繁体   English   中英

VB.NET 查询字符串有参数

[英]VB.NET querystring has parameter

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

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

伪代码:

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是否有价值。 我只想知道它是否在查询字符串中。

你很接近。 用:

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

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

这应该解决这两种情况:

<%@ 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