locked
Proper way to add a custom request header in HttpModule RRS feed

  • Question

  • User380035336 posted

    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?

    Thursday, April 11, 2013 12:49 PM

Answers

  • User-1241139641 posted

    OK good. Smile

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 11, 2013 1:33 PM

All replies

  • User-1241139641 posted

    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.

    Thursday, April 11, 2013 1:18 PM
  • User380035336 posted

    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.

    Thursday, April 11, 2013 1:23 PM
  • User-1241139641 posted

    OK good. Smile

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 11, 2013 1:33 PM