SharePoint 2013 Custom HttpModule for URL redirects not being loaded

October 16, 2012

When working on a recent SharePoint 2013 project I was looking into options for handling URL redirects. From previous experience the two options which came to mind immediately were either an HttpModule or the new URL Rewrite module in IIS 7.

I had a Google around for other options and there were a few such as additional IIS sites/virtual directories or using the SharePoint redirect page layout, however none of these gave me the functionality required so I was left with my original two options.

When reviewing the two choices I put together a list of the Pros and Cons. In terms of performance the URL rewrite module would be slightly better, however the HttpModule would provide greater flexibility as well as not requiring users to get onto the WFE server. In the end I decided the HttpModule would be the best approach but only if the impact on the performance was acceptable.

To track the performance I created a spreadsheet and picked 15 pages on the site. I then hit each page with the developer dashboard open and recorded the page load time. I visited each page 3 times and worked out the average load time for each.

I then created a basic HttpModule using an excellent blog post by Waldek Mastykarz, which dates back to SharePoint 2007 but is still applicable for SharePoint 2013. I then implemented my additional logic for my specific requirements. My plan was to deploy this code and test the same pages with the HttpModule loaded to determine the impact on the site. It was at this point I started encountering issues.

I deployed the DLL to the GAC and added the required sections in the web.config, however the redirects never worked. I checked the code and tried the usual debugging techniques but I could never hit any breakpoints. I even tried writing information out to a text file but nothing worked. I checked the DLL was in the GAC and double checked all my web.config settings but the module wasn’t getting loaded.

I had a Google around and came across some other examples of people implementing HttpModules but they all seemed to work the same.

Finally I came across a link on Microsoft TechNet forum which suggested the HttpModule needed to be registered under the <modules> section in <system.webserver> not under <httpModules> in <system.web>. As soon as I made this change my HttpModule started working.

I’m sure some people will think this is obvious but it took me a while to track down the issue so it may help some folks but if nothing else this post will act as a reminder for me 🙂

Advertisements

%d bloggers like this: