Our vendor's on premise web app (ASP.NET 3.5) supports user identification (authentication) via custom http request header.
I am writing an ASP.NET 3.5 HTTP module to add the custom request header to the current request. This header will represent the identity of the user. Another header will represent the role of the user. Currently running the code in VS2012 using .NET
3.5/VStudio Web Server.
var response = HttpContext.Current.Response;
var request = HttpContext.Current.Request;
NameValueCollection headers = new NameValueCollection();
headers["SSOLoginID"] = "foo";
request.Headers.Add(headers);
Unforunately, when I try to add the custom request header I get the error (System.PlatformNotSupportedException: Operation is not supported on this platform.).
Is this a limitation of VStudio Web server or is my code bad for adding a custom header to the current request?
Check out this HttpModule to add headers to request post, It shows how you can make it work using reflection. Request.Headers acts like
it is readonly so adding a new header throws an exception.
Finally got the code to work. I had to change from running/hosting the web app/http module from VS Web Server (Cassini) to IIS7.5. Once I switched to IIS 7.5 it works fine now.
I was just playing around with this in VS and with Cassini set to 'Classic' pipeline even setting headers in Page_Load doesn't work, but in Integrated mode it does. It looks like IIS does have something to do with it.
Member
38 Points
138 Posts
Proper way to add a custom request header in HttpModule
Apr 11, 2013 12:49 PM|skmcfadden|LINK
Our vendor's on premise web app (ASP.NET 3.5) supports user identification (authentication) via custom http request header.
I am writing an ASP.NET 3.5 HTTP module to add the custom request header to the current request. This header will represent the identity of the user. Another header will represent the role of the user. Currently running the code in VS2012 using .NET 3.5/VStudio Web Server.
var response = HttpContext.Current.Response;
var request = HttpContext.Current.Request;
NameValueCollection headers = new NameValueCollection();
headers["SSOLoginID"] = "foo";
request.Headers.Add(headers);
Unforunately, when I try to add the custom request header I get the error (System.PlatformNotSupportedException: Operation is not supported on this platform.).
Is this a limitation of VStudio Web server or is my code bad for adding a custom header to the current request?
Participant
1380 Points
316 Posts
Re: Proper way to add a custom request header in HttpModule
Apr 11, 2013 01:18 PM|psinet|LINK
Check out this HttpModule to add headers to request post, It shows how you can make it work using reflection. Request.Headers acts like it is readonly so adding a new header throws an exception.
Member
38 Points
138 Posts
Re: Proper way to add a custom request header in HttpModule
Apr 11, 2013 01:23 PM|skmcfadden|LINK
Finally got the code to work. I had to change from running/hosting the web app/http module from VS Web Server (Cassini) to IIS7.5. Once I switched to IIS 7.5 it works fine now.
Participant
1380 Points
316 Posts
Re: Proper way to add a custom request header in HttpModule
Apr 11, 2013 01:33 PM|psinet|LINK
OK good.
I was just playing around with this in VS and with Cassini set to 'Classic' pipeline even setting headers in Page_Load doesn't work, but in Integrated mode it does. It looks like IIS does have something to do with it.