开发者

Redirecting user from an old web to another in Sharepoint

I want to add the ability to redirect users when they visit certain old sites. The URL of the old sites are unknown, but the server name is the same, e.g.

Old site url:

http://sharepoint/mySite/default.aspx

New site url:

http://sharepoint/myNewSite/...

There are a lot of other pages within mySite, most 开发者_运维知识库of which must be redirected to the new site, but there are exceptions (e.g. user can still view the documents within the site). I thought I have to do this programmatically by somehow capturing the http request and read the url myself. Being no sharepoint guru, I had a quick google, and found that writing a web part is prehaps the best alternative for my situation.

But I'm just wondering, given my situation and needs, is writing a web part, or something programmatically, really the ideal solution? Or is there a faster and quicker way to achieve what I want using Sharepoint?

Thanks.


You can implement a System.Web.IHttpModule that listens to the System.Web.HttpApplication.BeginRequest event, detects whether the request url points to an old site and redirecing to the new site when necessary.

The Sharepoint part of this involves creating a Microsoft.SharePoint.Administration.SPWebConfigModification that adds the reference to your module into the web.config file of each web frontend that you have. If you implemented this as a Web Application-level feature, the code for the feature receiver activation method would look something like this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    var webApplication = (SPWebApplication)properties.Feature.Parent;
    var redirectionModuleType = typeof(MyRedirectionModule);
    var modification = new SPWebConfigModification()
    {
        Name = "add[@name='MyRedirectionModule']",
        Path = "configuration/system.web/httpModules",
        Owner = "MyModule",
        Sequence = 0,
        Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
        Value = "<add name=\"MyRedirectionModule\" type=\"" + redirectionModuleType.FullName + ", " + redirectionModuleType.Assembly.FullName + "\" />"
    };
    webApplication.WebConfigModifications.Add(modification);
    webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    webApplication.Update();
}


You can do it in three ways

  1. creating a custom HTTP Module (Good solution)
  2. Write a javascript code in your old site's master page to redirect to new page (location.href) (easy to create but navigation happens from client side)
  3. Write a webpart with a code for redirection and deploy in old site's master page (easier than point1 )


Rather than modifying the Master Page you can consider automatically injecting some JavaScript logic into each page of a site collection that handles the redirect.

Have a look at our free SharePoint Infuser tool.


If you are using a load balancer or a reverse proxy like ISA Server you could implement redirection rules at those levels.


Somebody made this for you already :)

See SharePoint Smart 404 Feature. It allows you to add redirect rules to create vanity urls and handle 404s nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜