【问题标题】:Retrieve GET variables from URL in ASPX从 ASPX 中的 URL 检索 GET 变量
【发布时间】:2010-11-05 05:38:23
【问题描述】:

检索传递给 .aspx (VB) 页面的 GET(在 URL 中)变量的最简单/标准方法是什么?

【问题讨论】:

标签: asp.net vb.net forms


【解决方案1】:

您可以使用以下内容:

示例网址:http://www.whatever.com?hello=goodbye&goodbye=hello

string value = Request.QueryString("hello");

价值将是再见

foreach(string key in Request.QueryString)
{
    Response.write(Request.QueryString(key))
}

【讨论】:

  • 我在使用 [ ] 时出现语法错误,但在使用 ( ) 时却没有
  • @ClayNichols 在这里相同。 Request.QueryString["hello"] 不起作用。 Request.QueryString("hello") 会。
  • 我冒昧地将 [ ] 更改为 ( )。后者是问题所在的 VB.NET 语法。
  • 2020 年 12 月,这对我不起作用。尝试记录值时只是得到一个空行。这仍然有效吗?
【解决方案2】:

如果你有路径:

www.stackoverEvan.com/question/directory-lookup.asp?name=Evan&age=16

如果你这样做:

Hi ,  <%= Request.QueryString("name") %>.  
Your age is  <%= Request.QueryString("age") %>. 

输出:

欢迎,埃文。你的年龄是 16 岁

但是当您在 VB 中指定它时,最佳方式如下:

路径:

http://localhost/script/directory/NAMES.ASP?Q=Evan&Q=Bhops

代码:

--- Names.asp --- 
<% 
  For Each item In Request.QueryString("Q") 
    Response.Write Request.QueryString("Q")(item) & "<BR>" 
  Next 
%> 

输出:

埃文
博普斯

【讨论】:

    【解决方案3】:

    查看 Request.QueryString 集合

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 2012-04-13
      • 2013-08-19
      • 2011-03-09
      • 2016-08-24
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多