asp-classic – 如何检查VBScript中是否存在POST提交字段?

前端之家收集整理的这篇文章主要介绍了asp-classic – 如何检查VBScript中是否存在POST提交字段?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
提交表单后,如果存在特定字段,如何检查服务器端?例如:
If [Exists] Request("FieldName") Then
    ...
End If

解决方法

检查它是否为空.有几种不同的方式,但我经常使用的方法是:
If Request("FieldName") <> "" Then
 'etc.
End If

我通常使用以下代码之一的某些变体显式检查Form和QueryString集合,如果我可能从一个或另一个获取变量,具体取决于上下文:

Select Case True
    Case Request.Form("FieldName") <> ""
        'Run if the Form isn't empty
    Case Request.QueryString("FieldName") <> ""
        'Run if the QueryString isn't empty
    Case Else
        'Set a predefined default if they're both empty
End Select

或嵌套的If …然后:

If Request.Form("FieldName") <> "" Then
    'Run if the Form isn't empty
ElseIf Request.QueryString("FieldName") <> "" Then
    'Run if the QueryString isn't empty
Else
    'Set a predefined default if they're both empty
End If

如果我确切地知道它来自哪个集合,我将专门检查该集合.原因是我想确保它从我期望它来自的地方拉出我所期望的.当我不期待它时,我不希望有人通过在QueryString中发送内容来覆盖Form值.

MSDN开始:

If the specified variable is not in one of the preceding five
collections,the Request object returns EMPTY.

All variables can be accessed directly by calling Request(variable)
without the collection name. In this case,the Web server searches the
collections in the following order:

  • QueryString
  • Form
  • Cookies
  • ClientCertificate
  • ServerVariables

If a variable with the same name exists in more than one collection,
the Request object returns the first instance that the object
encounters.

It is strongly recommended that when referring to members of a collection the full name be used. For example,rather than Request.(“AUTH_USER”) use Request.ServerVariables(“AUTH_USER”). This allows the server to locate the item more quickly.

猜你在找的asp.Net相关文章