我想修改我的HeaderResponse后登录功能。实际上,我可以使用以下内容修改/添加响应字段中的新部分
HttpContext.Response.AddHeader(“示例”,“示例”);
但它并不能影响所有的请求。它只影响一个请求。
[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之类的东西。有可能这样做吗?或者有什么替代的方法。
发布于 2017-04-08 15:54:48
要达到你想要达到的目标,有多种方法。
1.添加一个OWIN中间件
public override async Task Invoke(IOwinContext context) {
//call Headers.Add() method
context.Response.Headers.Add("key",value);
await Next.Invoke(context); }
2.添加基本控制器覆盖OnActionExecuting
以添加标头值
https://stackoverflow.com/questions/43301383
复制