2016-07-22 7 views
0

ASP.NETアプリケーション用の基本認証HTTPフィルターを作成しています。パイプラインを短絡させずにHttpActionContext応答にヘッダーを追加する方法

認証の一部として、レスポンスにヘッダーを追加する必要があります。フィルタが呼び出されると、actioncontext.Responseはnullになります。応答を作成すると、ヘッダーを追加できますが、パイプラインが短絡して実際のコントローラ機能が呼び出されることはありません。

認可を実装するために別の方法を使用する必要がありますか?

答えて

0

応答を更新するために、グローバルたAuthenticateRequestとPreSendRequestHeadersイベントを使用してください:その@Fanため

public class Global : HttpApplication 
{ 
    // The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request. 
    // Subscribing to the AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handler. 
    public void Application_AuthenticateRequest(object sender, EventArgs e) 
    { 
     // your authenticate code 
    } 

    public void Application_PreSendRequestHeaders(object sender, EventArgs e) 
    { 
     // your add heard code 
    } 
} 
+0

感謝を。私はそのアイデアを調査したが、間違った方法のように思えた。私は途中でヘッダーを生成するアクションフィルターを配線し、途中で応答に配置しました。現在のバージョンのASP.NETでこれを行うのは正しい方法だと思われます。 – Neil

関連する問題