views:

525

answers:

1

I've got an HttpModule in my application that hooks into the FormsAuthenticationModule's Authenticate event with the following code:

public void Init(HttpApplication context)
{
    FormsAuthenticationModule faModule =
        (FormsAuthenticationModule)context.Modules["FormsAuthentication"];
    faModule.Authenticate +=
        new FormsAuthenticationEventHandler(faModule_Authenticate);
}

Unfortunately, the call to context.Modules fails because the app needs to run in a medium-trust environment. Is there another way that I can hook into this event?

+2  A: 

That's a tough one - you can't even access the Modules collection from within your Global application file.

You could try calling your custom code from the AuthenticateRequest handler in Global:

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    // Call your module's code here..
}

You can't grab your custom module from the collection, either, so you'd need a static reference to your module's library.

Other than granting the AspNetHostingPermission (as detailed for other permissions here) to your site in the machine level web.config, I'm out of ideas!

Jarrod Dixon
If you check the Modules property in the HttpApplication class in System.Web via Reflector, you can see the CAS demand for a High trust level. Unfortunately, I know my hoster's response to asking: "We have these WONDERFUL VPS/Dedicated servers!" :(
Greg Hurlman
Yes, locked-down hosting is a problem - and I'm guessing your module is 3rd party?
Jarrod Dixon
No, it's my own, so I can put the code somewhere else, was just hoping to keep it separated.
Greg Hurlman