asp.net-2.0response.addheader

Response.AddHeader


When is Response.AddHeader used?


Solution

  • It's used to add additional HTTP Headers to your request-- read the previous link if you're unfamiliar wtih what an HTTP Header is used for.

    Most of the time, you'll end up setting headers indirectly, using other ASP.NET objects or methods like Response.Cookies or Response.Redirect. However, there are advanced, relatively unusual scenarios where it's sometimes necessary to call Response.AddHeader() directly in your code.

    For example, to cause an HTTP 301 (permanent) redirect in ASP.NET 3.5, you'd need to use Response.AddHeader, using code like this:

    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location","/newpage.aspx");
    }
    </script>