Aug062008

URL redirection or URL mapping in Sharepoint

Published by waqas at 7:40 PM under SharePoint

URL redirection in sharepoint can be done with many different ways, but the one I have most useful is to implement it via httpmodule.
Just use following piece of code to create httpmodule and update web.config of the web application to add that module entry and everything will work fine:

namespace BWL.RedirectModule
{
    public class Redirector : IHttpModule
    {
        public void Dispose()        { }        
        public void Init(HttpApplication context)       
        {
            context.BeginRequest +=new EventHandler(context_BeginRequest);
        }        
        void context_BeginRequest(object sender, EventArgs e)
        {      
            string domain = @"(beyond)(weblog|weblogs)(.com/*$)"; //specify your URL here to be checked for redirection
            HttpApplication app = (HttpApplication)sender;
            string requestUrl = app.Request.Url.ToString(); 

            if(Regex.IsMatch(requestUrl,domain))
                app.Response.Redirect("http://beyondweblogs.com/sites/bwlportal"); // if url is found, redirect it to the new url
        }        
    }
} 

Compile it as a dll, then copy this dll to the sharepoint web application bin folder. Finally, copy following line in the web application's web.config after <httpModules> <clear />

<add name="Redirector" type="BWL.RedirectModule.Redirector" />

enJoy!



[Digg] [Google] [Facebook]

Tags:

E-mail| Permalink | Trackback | Post RSSRSS comment feed 0 Responses

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading