Welcome to Office Zealot Sign in | Join | Help

URL Rewriting in Microsoft Office SharePoint Server

The new task for the team was making the URLs from SharePoint go friendly; basically remove the annoying “/Page/” string from the URL.  This has the added benefit that we’ll be able to keep our old URLs and keep Office Zealot rankings in search engines.

While not complicated, Sharepoint cares a lot about handlers.

In essence, we need to create an HTTP Module to handle requests and mangle the request URL to our heart’s content. The URL rewriting process has been hashed many times over in multiple places, so we won’t bore you with those details.

namespace Name

{

    public class ClassName : IHttpModule

    {

        public void Init(HttpApplication context)

        {

            context.BeginRequest += new EventHandler(context_BeginRequest);

        }

 
        private void context_BeginRequest(object sender, EventArgs e)

        {
            //Code to Handle the URL Rewrite

        }

 

        public void Dispose()

        {

        }

    }

} 

We need to sign the assembly and compile the project. Then add the dll to the global assembly cache and restart IIS to reload all the assemblies that SharePoint uses.

Then you need to add the following line on the HttpModules section in the web.config file of the web site you are going to use the Http Module.

<httpModules>

      <clear />

          <add name="Just a Name" type="Namespace.Class, Assembly Name, Version=x.x.x.x, Culture=neutral, PublicKeyToken=xxxxxxxxxxx" />


This line needs to be at the top so you can get the request before SharePoint does. This is important, since Sharepoint does its own rewriting…

And with this you are ready to go. There is still some testing to do, but those are the basics.

Adrian.

Published Wednesday, February 06, 2008 10:11 PM by omar2

Comments

No Comments
Anonymous comments are disabled