How to connect http-module to fire events only for certain types of pages

I have an http module on a sharepoint site, and this module creates its own class and adds it to the session and performs other initial steps for my site. However, I notice that the http module is called for all types of requests (.aspx, .js, .png, .jpg).

Is there a way for the HTTP module to be called only for certain types of .net pages?

+3
source share
6 answers

In IIS, you will configure a handler that will be associated with your specific extension so that the handler is applied only to that extension. JavaScript files should not be processed.

0
source

I would also look at this article , you are looking at integrating your module / handler with SharePoint anyway.

0
source

Although I like the ease of deploying this type of HTTP handler (and the fact that you do not need to deploy the web.config entry for the handler), in cases where you cannot use the _layouts directory OR you want to have a custom file extension, an alternative method is also used here (although IIS requires one manual configuration step, so it may not be suitable for "Without touch deployment")

1) Create your http handler, as usual for an asp.net application. You can add links to SharePoint DLLs and interact with the object model since you are in the application pool.

2) Add and go into your web.config to register the handler and determine the extension that you are going to use. IE:

3) Define your custom extension in IIS using IIS> SIte website properties> Home directory> Configuration> Mappings

In this case, we defined the .proxy extension that the handler will process. Our handler is a .NET assembly, so we need to add a mapping to route .proxy requests to .net isapi dll (C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ aspnet_isapi.dll) .. also make make sure you clean "

From comments on http://msdn.microsoft.com/en-us/library/bb457204.aspx

0
source

I have done a little more research, and it seems that there is no way to do what I intend. I will need to check the type of request and cancel from there.

Thanks to everyone for their answers.

D

0
source

You can do this very easily using the HttpModule (before making any calls to the expensive SharePoint object model) by checking the extension in the contents of the latest Uri.Segments

void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; Uri uri = app.Request.Url; string lastSegment = uri.Segments[uri.Segments.Length-1]; .. check your extension here an do nothing if it doesn't match. .. } 

We use this in our TinyURL implementation for SharePoint to ensure that the performance impact on regular URLs is almost 0.

0
source

Here is a simple example of how to filter requests by extension ... the example below excludes specific extensions from processing files.

 public class AuthenticationModule : IHttpModule { private static readonly List<string> extensionsToSkip = AuthenticationConfig.ExtensionsToSkip.Split('|').ToList(); // In the Init function, register for HttpApplication // events by adding your handlers. public void Init(HttpApplication application) { application.BeginRequest += new EventHandler(this.Application_BeginRequest); application.EndRequest += new EventHandler(this.Application_EndRequest); } private void Application_BeginRequest(Object source, EventArgs e) { // we don't have to process all requests... if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath))) return; Trace.WriteLine("Application_BeginRequest: " + HttpContext.Current.Request.Url.AbsoluteUri); } private void Application_EndRequest(Object source, EventArgs e) { // we don't have to process all requests... if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath))) return; Trace.WriteLine("Application_BeginRequest: " + HttpContext.Current.Request.Url.AbsoluteUri); } } 

In the configuration file, specify which extensions to exclude and run the list of extensions in the module.

0
source

All Articles