The ability to create simple URLs in a public site is important, especially for public web sites. One of my customers wants to use these simple links in paper ads and other documentations. Quite understandable.
A typical URL to available jobs on a MOSS site would be:
mysite.com/about/jobs
Or even worse, if it's a page and not a sub site:
mysite.com/about/Pages/jobs.aspx
Creating a nice link like "mysite.com/jobs" in standard MOSS would require you to create a sub site named "jobs" directly in the site collection. Not very nice if you like to structure your content properly.
A solution
A work-around would be to always only print the link to the start page (for example mysite.com) and guide the user from there. But that's too simple right, and not always sufficient. For ads, yes, for documentation that will be in play for a long time, no.
Instead, enter the HTTP module.
Basically, this is standard ASP.Net technology, and a great article about this approach can be found here:
http://msdn2.microsoft.com/en-us/library/ms972974.aspx
Step 1 - create the HTTP module class
In your Visual Studio solution, create a class similar to this (of course, choose a proper namespace):
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace MyNamespace
{
public class UrlRedirectHttpModule : IHttpModule
{
public virtual void Init(HttpApplication pApplication)
{
pApplication.BeginRequest += new EventHandler(BeginRequest);
}
public virtual void Dispose()
{
}
void BeginRequest(object pSender, EventArgs pArgs)
{
HttpApplication application = (HttpApplication)pSender;
// TODO: Implement simple link switching here.
if (application.Request.Path.EndsWith("a"))
{
application.Response.Redirect("http://www.google.com", true);
}
}
}
}
Step 2 - Modify web.config
Add the following line last into the "<system.web><httpModules>" section:
<add name="UrlRedirect" type="MyNamespace.UrlRedirectHttpModule, MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
Of course, modify the namespace name. Also specify PublicKeyToken if your assembly is signed. Which I recommend you do by the way.
Step 3 - Enhancement
I suggest you create a list in your SharePoint solution that basically contains the simple url in the first column, and the redirect url in the second column. These might or might not support regular expressions, depending on the targeted users/administrators of the simple url functionality.
In your "BeginRequest" event listener, simply do a look-up to the SharePoint list and check if a redirect should occur or not. Oh, and remember to cache the look-up as well for better performance. Note that this check will occur for every HTTP request!
That's it!
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment