简体   繁体   中英

Setting Header in ASP.NET MVC 4 Controller

I am trying to insert an header in my controller according with the parameter sub , but with no success. I have tried these two lines, here's the code:

public ActionResult Index(string sub)
{
    if (!string.IsNullOrEmpty(sub))
    {
        HttpContext.Response.Headers.Add("sub", sub);
        Response.AddHeader("sub", sub);
    }

    return View();
}

This may work for you..

public ActionResult Index(string sub)
{
    if (!string.IsNullOrEmpty(sub))
    {
        HttpContext.Response.AppendHeader("sub", sub);

    }
return View();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM