.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

SharePoint and HTTP Module

Posted By:Jean Paul       Posted Date: June 30, 2015    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article I would like to take you through deploying an HTTP module in SharePoint 2013.

In this article I would like to take you through deploying an HTTP module in SharePoint 2013.


Redirect users from accessing the Site Contents page (viewlsts.aspx).


Open Visual Studio and create a Class Library project.

Add a reference to the System.Web library.

Replace the class file with the following code where:

Class implements the IHttpModule interface
Redirection when URL contains viewlsts.aspx

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Web;  
using System.Web.UI;  
namespace SPModule  
    public class SPModule : IHttpModule  
        public void Dispose() { }  
        public void Init(HttpApplication context) { context.PreRequestHandlerExecute += context_PreRequestHandlerExecute; }  
        void context_PreRequestHandlerExecute(object sender, EventArgs e)  
            HttpApplication app = sender as HttpApplication;  
            if (app != null)  
                Page page = app.Context.CurrentHandler as Page;  
                if (page != null) { if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("_layouts/15/viewlsts.aspx")) { HttpContext.Current.Response.Redirect("http://www.bing.com"); } }  
Build the code and copy the DLL to the IIS SharePoint BIN folder as shown below.

Now, open the web.config and find the modules section. (Please note that there is another httpModules section that is not for our purpose.)

Add your class name in the format Assembly.ClassName. Save the changes.

Refresh your SharePoint site and try accessing the viewlsts.aspx page using the URL given below:


You should see the page is redirected to www.bing.com.


HTTP Module


In this article we saw how to use an HTTP Module within SharePoint. The source code is attached with the article.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend