using System;
using System.Web;
using System.Web.Caching;
using System.Configuration;
using System.Xml.Serialization;
namespace URLRewriter.Config
{
///
/// Specifies the configuration settings in the Web.config for the RewriterRule.
///
/// This class defines the structure of the Rewriter configuration file in the Web.config file.
/// Currently, it allows only for a set of rewrite rules; however, this approach allows for customization.
/// For example, you could provide a ruleset that doesn't use regular expression matching; or a set of
/// constant names and values, which could then be referenced in rewrite rules.
///
/// The structure in the Web.config file is as follows:
///
/// <configuration>
/// <configSections>
/// <section name="RewriterConfig"
/// type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
/// </configSections>
///
/// <RewriterConfig>
/// <Rules>
/// <RewriterRule>
/// <LookFor>pattern</LookFor>
/// <SendTo>replace with</SendTo>
/// </RewriterRule>
/// <RewriterRule>
/// <LookFor>pattern</LookFor>
/// <SendTo>replace with</SendTo>
/// </RewriterRule>
/// ...
/// <RewriterRule>
/// <LookFor>pattern</LookFor>
/// <SendTo>replace with</SendTo>
/// </RewriterRule>
/// </Rules>
/// </RewriterConfig>
///
/// <system.web>
/// ...
/// </system.web>
/// </configuration>
///
///
[Serializable()]
[XmlRoot("RewriterConfig")]
public class RewriterConfiguration
{
// private member variables
private RewriterRuleCollection rules; // an instance of the RewriterRuleCollection class...
///
/// GetConfig() returns an instance of the RewriterConfiguration class with the values populated from
/// the Web.config file. It uses XML deserialization to convert the XML structure in Web.config into
/// a RewriterConfiguration instance.
///
/// A instance.
public static RewriterConfiguration GetConfig()
{
if (HttpContext.Current.Cache["RewriterConfig"] == null)
HttpContext.Current.Cache.Insert("RewriterConfig", ConfigurationManager.GetSection("RewriterConfig"));
return (RewriterConfiguration) HttpContext.Current.Cache["RewriterConfig"];
}
#region Public Properties
///
/// A instance that provides access to a set of s.
///
public RewriterRuleCollection Rules
{
get
{
return rules;
}
set
{
rules = value;
}
}
#endregion
}
}