2

I need to add a custom header something like MYName: Balaji which i need to access from .aspx file through Request.ServerVariables["HTTP_MYName"]; should return "Balaji". I need so many variables like this it will added dynamically. Kindly help.

Also, I cannot persist this varaibles in any of the .Net controls or objects like cookies, sessions, application, hidden variable etc., or cannot store this in d/b and get it back whenever is required, I NEED IT ONLY IN HTTP HEADERS.

Kindly send the C# code how to add this variable and get the value back in .aspx file.

1 Answer 1

1

What do you mean by "get the value back in .aspx file"? HTTP headers are intended to be used as directives to a browser, how to interpret the given content. You don't have access to these values in your document.

Setting a custom HTTP header is quite easy, however:

   Page.Response.AddHeader("MyCustomHeader", "VerySecretValue")

Updated my answer as per your comment. If you need to transfer information between a HTTPModule and an ASPX page, you can use HTTPContext.Current, since this stays the same in both places. So, you add it by

  HttpContext.Current.Items.Add("SecretKey", "SecretValue");

and read it as

  string s = HttpContext.Current.Items["SecretKey"];
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, got your point. Is it possible to set the value somewhere (either in httpmodule or httphandler) and get it back through Request.ServerVariables["<MyKey>"]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.