I need to modify the content of certain HttpRequests (SSAS connection strings) in IIS. Basically, I need to add an element to the SOAP contained in the request.
My approach so far has been to add a Filter to the HttpRequest, and perform the change in the filter's Read method. As far as I can tell, though, Read is never being executed.
My understanding of the Request.Filter is that it gets read from when IIS processes the request, so IIS should see my modified Request.
Is what I'm trying to do actually possible using an HttpModule and is my Filter approach correct?
If so, what would cause Read to not be hit?
Here's a simplified version of my code:
public class CustomHttpModule : IHttpModule {
private HttpApplication app;
public string ModuleName {
get { return "CustomHttpModule"; }
}
public void Init(HttpApplication context) {
app = context;
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e) {
var request = app.Context.Request;
request.Filter = new CustomHttpFilter(request.Filter);
}
}
public class CustomHttpFilter : Stream {
private Stream outputStream;
public CustomHttpFilter(Stream outputFilter) {
outputStream = outputFilter;
}
public override int Read(byte[] buffer, int offset, int count) {
// read and make the necessary changes
}
}