2016-10-31 8 views
0

BundleConfig ScriptBundleを使用して作成された仮想パス/ルートで送信されたリクエストのパラメータを検証する方法はありますか?BundleConfigルート/ URLのリクエストの検証

例:私は値を検証するにはどうすればよい

http://example.com/bundles/bjqs?v=parameter-value_to%be+validated

:ユーザーは次のような要求を送信した場合

bundles.Add(new ScriptBundle("~/bundles/bjqs").Include(
       "~/Scripts/bjqs-1.3.js")); 

:以下のように

私はBundleConfig構成を持っています要求文字列をASP.NETで処理/処理する前に、正規表現に対してパラメータを渡しましたか?

答えて

1

カスタムHttpModuleを使用してリクエストを代行受信することができます。例:

public class MyModule1 : IHttpModule 
{ 
    public void Dispose() {} 

    public void Init(HttpApplication context) 
    { 
     context.AuthorizeRequest += context_AuthorizeRequest; 
    } 

    void context_AuthorizeRequest(object sender, EventArgs e) 
    { 
     var app = (HttpApplication)sender; 

     // Check if the parameter is valid, your logic 
     if (ValidateRequest(app.Context.Request)) 
     { 
      // Then do nothing 
      return; 
     } 

     // Otherwise, return unauthorized response 
     app.Context.Response.StatusCode = 401; 
     app.Context.Response.End(); 
    } 
} 
関連する問題