Wednesday, November 5, 2014

Steps - HTTPModule to redirect mngsiteadmin.aspx page


  1. Open vsual studio
  2. Create a class library project
  3. add system.web reference
  4. inherit IHttpModule
  5. Put the code below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace ModuleHttp
{
    public class ModuleRedirect1 : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }
        void context_BeginRequest(object sender, EventArgs e)
        {
            // throw new Exception("The method or operation is not implemented.");
            HttpApplication oApp = (HttpApplication)sender;
            if (oApp.Request.RawUrl.Contains("/_layouts/mngsiteadmin.aspx"))
            {
                oApp.Response.Redirect(oApp.Request.RawUrl.Remove(oApp.Request.RawUrl.LastIndexOf("/")) + "/copy_mngsiteadmin.aspx");
            }
        }
        public void Dispose()
        {
        }
    }
}

6. deploy the code
7. put the code in assembly / GAC

8. add reference to web.config under <modules runAllManagedModulesForAllRequests="true">

<add name='MyHttpModule' type='ModuleHttp.ModuleRedirect1,ModuleHttp,Version=1.0.0.0,Culture=neutral, PublicKeyToken=f2b9e495ae2296c1' />

<add name='ANY NAME' type='NAMESPACE.CLASSNAME,NAMESPACE,Version=1.0.0.0,Culture=neutral, PublicKeyToken=f2b9e495ae2296c1' />

9. MOST IMPORTANT - DO IISRESET . changes may not reflect else.

No comments:

Post a Comment