2009-06-23 44 views
19

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

+0

下面是一个SO循环GET回发值的例子。 [http://stackoverflow.com/questions/562943/looping-through-a-request-querystring-in-vb-net](http://stackoverflow.com/questions/562943/looping-through-a-request- querystring-in-vb-net) – Zachary 2009-06-23 16:08:45

回答

43

您可以使用以下方法:

http://www.whatever.com?hello=goodbye&goodbye=hello 

string value = Request.QueryString("hello") 

值将告别

foreach(string key in Request.QueryString) 
{ 
    Response.write(Request.QueryString[key]) 
} 
+0

使用[]时出现语法错误,但在使用() – 2015-11-23 17:08:29

7

看那的Request.QueryString集合

0

如果你有一个路径:

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

输出:

Evan
Bhops