RequestValidationSource 列挙型

定義

検証する HTTP 要求データの種類を表します。

public enum class RequestValidationSource
public enum RequestValidationSource
type RequestValidationSource = 
Public Enum RequestValidationSource
継承
RequestValidationSource

フィールド

Cookies 2

要求クッキー。

Files 3

アップロードされたファイル。

Form 1

フォーム値。

Headers 7

要求ヘッダー。

Path 5

仮想パス。

PathInfo 6

HTTP PathInfo 文字列 (URL パスの拡張子)。

QueryString 0

クエリ文字列。

RawUrl 4

生の URL (URL のドメインに続く部分)。

次の例は、クエリ文字列値に対して特定の文字列のみを許可するカスタム要求検証コントロール クラスを作成する方法を示しています。

Imports System.Web  
Imports System.Web.Util  

Public Class CustomRequestValidation  
    Inherits RequestValidator  

Protected Overloads Overrides Function IsValidRequestString( _  
        ByVal context As HttpContext, _  
        ByVal value As String, _  
        ByVal requestValidationSource__1 As RequestValidationSource, _  
        ByVal collectionKey As String, _  
        ByRef validationFailureIndex As Integer) As Boolean  
    validationFailureIndex = -1  
    ' Set a default value for the out parameter.  
    ' This application does not use RawUrl directly, so you can   
    ' ignore the check for RequestValidationSource.RawUrl.  
    If requestValidationSource = RequestValidationSource.RawUrl Then  
        Return True  
    End If  

    ' Allow the query-string key "data" to have an XML-like value.  
    If (requestValidationSource = _  
            (RequestValidationSource.QueryString) AndAlso _  
            (collectionKey = "data") Then  
        ' The querystring value "<example>1234</example>" is allowed.  
        If value = "<example>1234</example>" Then  
            validationFailureIndex = -1  
            Return True  
        Else  
            ' Leave any further checks to ASP.NET.  
            Return MyBase.IsValidRequestString(context, value, _  
                requestValidationSource__1, collectionKey, _  
                validationFailureIndex)  
        End If  
    Else  
        ' All other HTTP input checks fall back to   
        ' the base ASP.NET implementation.  
        Return MyBase.IsValidRequestString(context, value, _  
            requestValidationSource__1, collectionKey, _  
            validationFailureIndex)  
    End If  
End Function  
End Class  
using System;  
using System.Web;  
using System.Web.Util;  

public class CustomRequestValidation : RequestValidator  
{  
    public CustomRequestValidation() {}  

    protected override bool IsValidRequestString(  
        HttpContext context, string value,   
        RequestValidationSource requestValidationSource, string collectionKey,   
        out int validationFailureIndex)  
    {  
        //Set a default value for the out parameter.  
        validationFailureIndex = -1;  

        // This application does not use RawUrl directly,   
        // so you can ignore the check for RequestValidationSource.RawUrl.  
        if (requestValidationSource == RequestValidationSource.RawUrl)  
            return true;  

        // Allow the query-string key "data" to have an XML-like value.  
        if (  
            (requestValidationSource == RequestValidationSource.QueryString) &&  
            (collectionKey == "data")  
           )  
        {  
            // The querystring value "<example>1234</example>" is allowed.  
            if (value == "<example>1234</example>")  
            {  
                validationFailureIndex = -1;  
                return true;  
            }  
            else  
           // Leave any further checks to ASP.NET.  
                return base.IsValidRequestString(context, value,   
                requestValidationSource, collectionKey, out   
                validationFailureIndex);  
        }  
        // All other HTTP input checks fall back to   
        // the base ASP.NET implementation.  
        else  
        {  
            return base.IsValidRequestString(context, value,   
                requestValidationSource, collectionKey,   
                out validationFailureIndex);  
        }  
    }  
}  

次の例は、カスタム検証コントロールを使用 ASP.NET を構成する方法を示しています。

<httpRuntime requestValidationType="CustomRequestValidation" />  

注釈

型を実装することで、カスタム要求検証型を作成 RequestValidator できます。 メソッド ASP.NET を呼び出して要求を検証すると、ASP.NET 検証するデータのソースを指定するパラメーター IsValidRequestString requestValidationSource が渡されます。 列挙 RequestValidationSource 体は、検証される要求データのソースまたは種類を指定するために使用されます。 列挙体は、 メソッドの パラメーターで渡される HTTP value 入力の種類を示 IsValidRequestString します。 カスタム ロジックを使用して検証しない場合は、HTTP 入力の基本要求検証実装に戻る方法として 列挙を使用できます。

次の表は、 メソッドの および パラメーターの値が列挙型の各メンバーに対 collectionKey value して解釈 RequestValidator.IsValidRequestString される方法を示 RequestValidationSource しています。

列挙型メンバー collectionKey パラメーター value パラメーター
Cookies コレクション内のクッキーの名前。 コレクション内の値。
Files コレクション内のアップロードされたファイルの名前。 コレクション内のアップロードされたファイルの値。
Form コレクション内のフォーム パラメーターの名前 コレクション内のフォーム パラメーターの値。
Headers コレクション内の HTTP ヘッダーの名前。 コレクション内の HTTP ヘッダーの値。
Path null ( Path は値のコレクションではありません)。 Path フィールドの値。
PathInfo null ( PathInfo は値のコレクションではありません)。 PathInfo フィールドの値。
QueryString コレクション内の query-string パラメーターの名前。 コレクション内の query-string パラメーターの値。
RawUrl null ( RawUrl は値のコレクションではありません)。 RawUrl フィールドの値。

適用対象

こちらもご覧ください