3

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();
}
Samuel Caillerie
  • 8,259
  • 1
  • 27
  • 33
Wellington Zanelli
  • 1,894
  • 3
  • 18
  • 43

1 Answers1

8

This may work for you..

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

    }
return View();
}
K D
  • 5,889
  • 1
  • 23
  • 35
  • Thank you, this worked for me, but now I have another problem. My header is like an array, because previously I have setted the value "0" in it. How can I clear this header before setting it again? Now the header is like: "xxxxx, 0" where 0 is the previous value. – Wellington Zanelli May 28 '13 at 12:31
  • Check if header exists first using Headers.AllKeys() and remove if it already exists.. – K D May 28 '13 at 12:56