views:

644

answers:

3

Hey guys / gals,

I will try to be as specific as I can be. I inherited a very antiquated C++ ISAPI filter that secures a classic ASP website and was tasked with the job of creating an HTTPModule to directly replace it.

First I hooked into the OnPreRequestHandlerExecute event. I then successfully recreated the calls to the stored procs that the original ISAPI filter made. Those calls return a statusCode which I toss into a CASE statement and depending on the status code, set a "redirection" string variable (sUrl). For example statusCode 15 will set sUrl to "/Session/Login.asp". This all works successfully.

The next step is the actual "redirect" of the page. In C++ the module was doing the following:

Headers.push_back(HeadersList::value_type("url", "/Session/Errors/SecurIDRequired.asp"));

I am attempting to recreate this functionality by using the following:

HttpContext.Current.RewritePath(sUrl);

This works 100% for all classic asp pages. The problem creeps up when the user trys to access "http://somedomain.com/Blah.jpg. The module successfully runs, sets the proper statusCode of 15, and the RewritePath method is called, but does not rewrite the URL to the login page. The same thing happens for any non classic ASP page.

So I started looking at other options instead of RewritePath and looked at TransferRequest. This looked promising so I changed the code to:

HttpContext.Current.Server.TransferRequest(sUrl, true);

This now routes all requested file types to the login page but bizarre things occur. First off I get the following client side errors in FireBug:

syntax error https://somedomain.com/JS/jQuery/jquery.js Line 2

... some other javascript errors that revolve around jQuery. I look at the Net panel, and it successfully loaded the jQuery library so I am at a loss with this (this does not happen with the RewritePath method).

Finally, I attempted to use good old Server.Transfer and got this server side error:

No http handler was found for request type 'GET'

Phew! I hope my explanation was adequate :)

I guess my real question is this, what is the best way to accomplish what I am attempting to accomplish. I feel as though the RewritePath method is the best, any tips would be greatly appreciated.

Cheers!

EDIT:

The handlers contained within the web.config are as follows:

<httpHandlers>
    <remove verb="*" path="*.asmx" />
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpHandlers>
A: 

It sounds like IIS is not handing the requests for images over to ASP.Net, which is the default (IIS just serves up images usually without handing it over to a Page or anything).

Have you tried mapping the image extensions to your custom handler, either in IIS or using the web.config file?

womp
Not sure, but nokturnal mentioned "any non classic ASP page" so I assume that means .aspx requests aren't working correctly either.
tk-421
That is correct, it is not working for ASPX pages as well.
nokturnal
Same case. It smacks of handler issues to me. If he's upgrading a classic asp site, the handler settings may not be in place for .aspx either.
womp
The site files have been moved to a new IIS7 site (which is using integrated pipeline mode obviously).
nokturnal
So have you checked the handler mappings?
womp
Just on the transit home now. I will try to check it out when I get there. Thanks a bunch guys, this is really bugging me :)
nokturnal
WOMP, please see my edit above to see the handlers that are contained within the web.config>
nokturnal
Ok, that looks good... can you check your IIS admin settings to make sure that there are settings for .aspx handlers as well? Navigate to the web application and check the Handler Settings ...
womp
Sorry for the delay but I won't be back until Sunday guys. Thanks for the interest in the thread and thanks for the help on this!
nokturnal
This problem has come back to bite me in the ass, so I had to revisit this thread :) womp, I have looked at the IIS7 settings and the following is listed for handlers for .ASPX:PageHandlerFactory-ISAPI-2.0-64, PageHandlerFactory-ISAPI-2.0, PageHandlerFactory-ISAPI-4.0_32bit + 64bit map to C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dllPageHandlerFactory-Integrated-4.0, PageHandlerFactory-Integrated map to System.Web.UI.PageHandlerFactory...Does this help at all?
nokturnal
A: 

I don't know if this is the best way to go, but as a test does something like the following work?

In your HttpModule:

private void Application_BeginRequest(Object source, EventArgs e)
{
    HttpContext context = ((HttpApplication)source).Context;
    HttpRequest request = context.Request;
    if(request.Url.ToString().Contains("blah.jpg"))
    {
        context.RewritePath("~/login.aspx?");
    }
}
tk-421
It would be rewriting to a classic ASP page not an ASPX resource. Also, if I utilize the BeginRequest event I get the same clientside errors as when I am using the Server.Transfer method.
nokturnal
A: 

Man, I am so sorry to waste everyone's time.

It turns out that the underlying data structure had some issues (permissions were not set correctly). Due to the complexity of the implemented security model, I must have missed that over and over again until finally I realized the problem. I must have looked at it 100 times and not realized it!

Thanks for all the replies and sorry again guys.

nokturnal