如何在 VB.NET 中使用 post 和 get 值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36152364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use post and get values in VB.NET?
提问by Nightwolf
I recently took over a web based project that is written vb.net (written by someone that did not know vb.net before he started).
我最近接手了一个写 vb.net 的基于 web 的项目(由一个在开始之前不了解 vb.net 的人写的)。
The current project used webforms and onclick triggers to get form values. It never posts any html form data.
当前项目使用 webforms 和 onclick 触发器来获取表单值。它从不发布任何 html 表单数据。
Here is a base example to show what I need to know:
这是一个基本示例,用于展示我需要了解的内容:
login.aspx
登录.aspx
<form name="LoginForm" action="auth.aspx?ref=LoginForm" method="post">
<input type="text" name="username" />
<input type="password" name="passphrase" />
<input type="submit" value="Login">
</form>
auth.aspx.vb
身份验证文件
Dim ref as String = ???
Dim username As String = ???
Dim passphrase As String = ???
Dim strSQL As String = "SELECT usrId FROM Users WHERE UserName =@ParamName AND Password =@ParamPass"
dbCommand = New SqlCommand(strSQL, dbConn)
dbCommand.Parameters.AddWithValue("@UserName", username)
dbCommand.Parameters.AddWithValue("@ParamPass", passphrase)
dr = dbCommand.ExecuteReader
How assign these post and get values to these variables?
如何将这些 post 和 get 值分配给这些变量?
回答by Allan S. Hansen
For your problem I would think this would work:
对于您的问题,我认为这会起作用:
Dim ref as String = Request.Querystring("ref")
Dim username As String =Request.Form("username")
Dim passphrase As String = =Request.Form("passphrase")
As mentioned in my comment, if not using the asp.net webform functionality, you'll have to rely on the (basically) ASP version of functionality.
Check here for more information: http://www.w3schools.com/asp/coll_form.asp
正如我在评论中提到的,如果不使用 asp.net webform 功能,您将不得不依赖(基本上)ASP 版本的功能。
在这里查看更多信息:http: //www.w3schools.com/asp/coll_form.asp

