Saturday, November 27, 2010

HTTP Module in sharepoint

Share/Save/Bookmark

In one of the scenario i got to replace the application page(new.aspx) with my custom application page(customnew.aspx). so quickly i got the new application page but then started wondering how to link this page to sharepoint without adding a new link but just replacing the existing link?
here is one of the solution implementing IHTTPModule..

public class Class1 : IHttpModule
    {
        public void Init(HttpApplication app)
        { 
            app.PreRequestHandlerExecute +=new EventHandler(app_PreRequestHandlerExecute);

        
        }
        void app_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpContext context = HttpContext.Current;
            if(context.Request.Path.Contains("/_layouts/new.aspx"))
            {
                string url = "customnew.aspx";
                if (!context.Request.QueryString.Equals("{}"))
                {
                    url = url + '?' + context.Request.QueryString;
                }
                context.Response.Redirect(url);
            }
        }
        public void Dispose()
        {
        }
}


Add the reference of this new httpmodule in web.config under HttpModules.

  Subscribe

No comments:

Post a Comment