0


I want to replace an old ISAPI filter that ran on IIS6. This filter checks if the request is of a special kind, then manipulates the header and continues with the request. Two headers are added in the manipulating method that I need for calling another special ISAPI module.
So I have ISAPI C++ code like:

DWORD OnPreProc(HTTP_FILTER_CONTEXT *pfc, HTTP_FILTER_PREPROC_HEADERS *pHeaders)
{
    if (ManipulateHeaderInSomeWay(pfc, pHeaders))
    {
        return SF_STATUS_REQ_NEXT_NOTIFICATION;
    }
    return SF_STATUS_REQ_FINISHED;
}

I now want to rewrite this ISAPI filter as a managed module for the IIS7. So I have something like this:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
}

And now what? The request seems not to do what it should?
I already wrote an IIS7 native module that implements the same method. But this method has a return value with which I can tell what to do next:

REQUEST_NOTIFICATION_STATUS CMyModule::OnMapRequestHandler(IN IHttpContext *pHttpContext, OUT IMapHandlerProvider *pProvider)
{
    if (DoSomething(pHttpContext))
    {
        return RQ_NOTIFICATION_CONTINUE;
    }
    return RQ_NOTIFICATION_FINISH_REQUEST;
}

So is there a way to send my manipulated context again?

Simon Linder
  • 3,378
  • 4
  • 32
  • 49
  • When you are in the ASP.Net pipeline, your HttpHeader are abstracted into the Request.Headers collection. I think you want to manipulate the values in that collection and continue in the ASP.Net pipeline as-usual afterwards. – Marvin Smit Mar 19 '10 at 13:32
  • I don't manipulate the values in the collection but add two additional headers called "url" and "ORIGINALURL" to the collection. The values of the "url" header points to a relative path of a DLL that I use and the "ORIGINALURL" header gets the originally sent url as value. – Simon Linder Mar 19 '10 at 13:38
  • So, when you reach your HttpHandler for the request, those entries are not present anymore? What is your intented functionality? normally you hook up the IHttpModule in the "Init" method to a "PostAuthorize" event (or any other event you think is appropriate). The functionality executes in the ASP.Net pipeline as a filter, and eventually ends up in a HttpHandler. What is the functionality that is not working for you? Or am i misreading your question? (The functionality that NEEDS these added headers, is it reading the Request.Headers or trying to read the headers from the Http stream? – Marvin Smit Mar 19 '10 at 13:44
  • The request looks like myurl.com/myModule?key=someValue. If I get such a request I have to send the request to a DLL that lies in a virtual folder of my website. This would be the path of the "url" header. The "ORIGINALURL" value is then used by this url to load a resource that is specified by "someValue". – Simon Linder Mar 19 '10 at 13:50
  • So, if i understand it correctly it's basically a dynamic redirect.Looking at your example URL it does not contain a filename extensions which makes it a little harder. If you can modify this (i.e. have an extension) you can map that extension on a Handler. With this handler you basically implement whatever the functionality is you need. You could implement a handler that does the functionality you desribe (call another endpoint passing in additional header, using the WebClient class for instance) – Marvin Smit Mar 19 '10 at 14:03
  • Ok, I'll try that... on monday. – Simon Linder Mar 19 '10 at 14:23
  • @Marvin: Solved it, nevertheless thanks for your help! – Simon Linder Mar 22 '10 at 14:11

1 Answers1

0

I finally found it. As I stated in the comments I add two headers to the request that are needed by my DLL that finally handles the request. The url header contains the path to the DLL. So I have to do a redirect to that DLL.
This is done with the following code:

private void OnMapRequestHandler(HttpContext context)
{
    ManipulateHeaderInSomeWay(context);
    string url = context.Request.Header["url"]; // path of the DLL

    // now this is the important call!
    context.Server.TransferRequest(url, true);
}
Simon Linder
  • 3,378
  • 4
  • 32
  • 49