Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading HTTP Request custom Headers

I am working on ASP.NET MVC 2 application. the website runs under SiteMinder (3rd party agent) for authentication. The Siteminder injects custom header to the incoming HTTP request. But when I try to read the custom header, I donot get the value.

System.Web.HttpContext.Current.Request.ServerVariables["CustomKey"];

Looks like these custom headers are getting stripped by MVC. I hav eensured that the headers are for sure getting injected by SiteMinder.

Am I doing anything wrong while reading as shown above?

like image 667
MeghanaK Avatar asked Dec 10 '10 18:12

MeghanaK


People also ask

How do I read HTTP headers?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.

Can HTTP headers be custom?

Custom HTTP headers can be used to filter requests or specify a value for the Accept header.

Can I add custom header to HTTP request?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.


1 Answers

You're looking for HttpRequest.Headers, not ServerVariables which represent variables served by IIS to the application:

System.Web.HttpContext.Current.Request.Headers["CustomKey"];
like image 88
Julien Lebosquain Avatar answered Jan 04 '23 17:01

Julien Lebosquain