2017-04-08 8 views
0

ログイン後にHeaderResponseを変更したいと思います。実際に私はこれで応答フィールドの新しいセクションを変更/追加することができますすべてのxhrリクエストのヘッダーを変更したい

HttpContext.Response.AddHeader( "例"、 "例");

しかし、それはすべての要求に影響しません。 1つの要求にのみ影響します。

[HttpPost] 
     [Route("Account/Login")] 
     [ValidateAntiForgeryToken] 

     public JsonResult Login(string username, string password) 
     { 
      AccountModel am = new AccountModel(username, password); 
      am.Find(username); 
      if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || 
       am.Login(username, password) == null) 
      { 

       var data = new { status = "false", message = "Account is Invalid" }; 

       return Json(data,JsonRequestBehavior.AllowGet); 
      } 

      ////////HttpContext.Response.AddHeader("Example", "example"); 

      return Json(....,JsonRequestBehavior.AllowGet); 
     } 

基本的には、ログインの進行後にHeaderResponseを作成します。私は、私はHttpGlobalContext.Responseのようなものが必要と思います。それは可能ですか?あるいは、それに代わる方法がありますか?

+0

はowinあなたを使用しているヘッダ値を追加するOnActionExecutingをオーバーライド2.Adding OWINミドルウェア

public override async Task Invoke(IOwinContext context) { //call Headers.Add() method context.Response.Headers.Add("key",value); await Next.Invoke(context); } 

を1.Adding

? –

+0

はい、私はowinを使用しています。 – Cracked

答えて

0

達成しようとしていることを達成するには、複数の方法があります。ベースコントローラが

関連する問題