I have implemented a custom UrlAuthorization module as shown here
The code is as follows:
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 have to call init from within every single one of my pages on load or开发者_运维问答 is there a way to set IIS to do it automatically with every load.
This question is probably very dumb....
You have to hook up the module in the web.config. For example:
<configuration>
<system.web>
<httpModules>
<add type=
"MattsStuff.CustomUrlAuthorizationModule, MattsStuff"
name="CustomUrlAuthorizationModule" />
</httpModules>
</system.web>
</configuration>
As long as you register your HTTPModule within the web.config, IIS will set it up for you.
Init is called as the initialization of your module, then you add the handler to the respective context event to handle, therefore it will respond to all requests.
精彩评论