Brett's SharePoint Blog

By Popular Demand... More HttpModule Sample Code

Several folks have asked for this, so here it is... the two other pieces of the ResourceRedirect solution from my LAYOUTS branding post. They're also the least interesting, which is why I didn't post them before. :)  Enjoy... review this post for the full context.

Redirect.cs

using System;

using System.Collections.Generic;

using System.Text;

namespace MOSS.Branding

{

public struct Redirect

{

public string pattern;

public string masterPageUrl;

public string originalMaster;

public string destinationPageUrl;

public Redirect(string _pattern, string _masterPageUrl, string _originalMaster, string _destinationPageUrl)

{

pattern = _pattern;

masterPageUrl = _masterPageUrl;

originalMaster = _originalMaster;

destinationPageUrl = _destinationPageUrl;

}

}

}

RedirectSectionHandler.cs

using System;

using System.Collections;

using System.Collections.Generic;

using System.Text;

using System.Configuration;

using System.Xml;

 

namespace MOSS.Branding

{

class RedirectSectionHandler : IConfigurationSectionHandler

{

#region IConfigurationSectionHandler Members

public object Create(object parent, object configContext, System.Xml.XmlNode section)

{

ArrayList coll = new ArrayList();

XmlElement root = (XmlElement)section;

 

string pattern = "";

string masterPageUrl = "";

string originalMaster = "";

string destinationPageUrl = "";

foreach (XmlNode parentNode in root.ChildNodes)

{

XmlNode patternNode = parentNode.Attributes.GetNamedItem("pattern");

if (patternNode != null) pattern = patternNode.InnerText.ToLower();

XmlNode originalMasterNode = parentNode.Attributes.GetNamedItem("originalMaster");

if (originalMasterNode != null) originalMaster = originalMasterNode.InnerText.ToLower();

XmlNode masterPageUrlNode = parentNode.Attributes.GetNamedItem("masterPageUrl");

if (masterPageUrlNode != null) masterPageUrl = masterPageUrlNode.InnerText.ToLower();

XmlNode destinationPageUrlNode = parentNode.Attributes.GetNamedItem("destinationPageUrl");

if (destinationPageUrlNode != null) destinationPageUrl = destinationPageUrlNode.InnerText.ToLower();

if ((masterPageUrl.Length == 0) && (destinationPageUrl.Length == 0)) throw new ConfigurationErrorsException("Redirects (masterPageUrl and destinationPageUrl) cannot both be blank.");

if ((pattern.Length == 0) && (originalMaster.Length == 0)) throw new ConfigurationErrorsException("Inputs (originalMaster and pattern) cannot both be blank.");

Redirect redirect = new Redirect(pattern, masterPageUrl, originalMaster, destinationPageUrl);

coll.Add(redirect);

}

return coll;

}

#endregion

}

}

Published Wednesday, February 27, 2008 6:22 PM by bgeoffro
Filed under:
Anonymous comments are disabled

About bgeoffro

I'm a senior consultant with Microsoft Consulting Services, focusing exclusively in SharePoint technologies. I've been at Microsoft and working with SharePoint since 2005. Previous to that, I'd been working in the portals/content management/enterprise search space since 2000 with Java-based competitor's products (Documentum, Vignette, Verity, BEA). My professional experience in the IT field goes back to the mid-90s, though general IT experience extends all the way back to authoring my first BASIC program for the Commodore 64 in 1982.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker