Calling custom module UrlAuthorization with every page load
I have implemented a custom UrlAuthorization module as shown here
The code looks like this:
public class CustomUrlAuthorizationModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
}
void context_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication context = (HttpApplication)sender;
if (context.User != null && context.User.Identity.IsAuthenticated)
{
HttpContext _httpContext = context.Context;
SiteMapNode node = SiteMap.Provider.FindSiteMapNode(_httpContext);
if (node == null)
throw new UnauthorizedAccessException();
}
}
public void Dispose()
{
}
}
My question is, do I need to translate init from every page to boot, or is there a way to set IIS to do this automatically on every boot.
This question is probably very dumb ....
+2
Matt
source
to share
2 answers
As long as you register your HTTPModule in the web.config file, IIS will configure it for you.
Init is called as your module initializes, then you add a handler to the appropriate context event to handle, so it will respond to all requests.
+2
Mitchel Sellers
source
to share
You need to include the module in your web.config file. For example:
<configuration>
<system.web>
<httpModules>
<add type=
"MattsStuff.CustomUrlAuthorizationModule, MattsStuff"
name="CustomUrlAuthorizationModule" />
</httpModules>
</system.web>
</configuration>
+4
G-wiz
source
to share