Asp – IIS Integrated Request Processing Pipeline — Modify Request

asp.nethttpmoduleiis-7

I want to implement an ISAPI filter like feature using HttpModule in IIS7 running under IIS Integrated Request Processing Pipeline mode.

The goal is to look at the incoming request at the Web Server level, and inject some custom HttpHeaders into the request. (for ex: HTTP\_EAUTH\_ID)

And later in the page lifecycle of an ASPX page, i should be able to use that variable as

string eauthId = Request.ServerVariables["HTTP\_EAUTH\_ID"].ToString();

So implementing this module at the Web Server level, is it possible to alter the ServerVariables collection ??

Best Answer

HttpRequest.ServerVariables Property is a read-only collection. So, you cannot directly modify that. I would suggest storing your custom data in httpcontext (or global application object or your database) from your httpmodule and then reading that shared value in the aspx page.

If you still want to modify server variables, there is a hack technique mentioned in this thread using Reflection.