| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Configuration;
- namespace SiteCore.URLRewriter
- {
- // Define a custom section containing a simple element and a collection of the same element.
- // It uses two custom types: UrlsCollection and UrlsConfigElement.
- public class UrlsConfig
- {
- public static UrlsSection GetConfig()
- {
- return (UrlsSection)ConfigurationManager.GetSection("RewriterRule");
- }
- }
- public class UrlsSection : ConfigurationSection
- {
- [ConfigurationProperty("urls", IsDefaultCollection = false)]
- public UrlsCollection Urls
- {
- get
- {
- return (UrlsCollection)this["urls"];
- }
- }
- }
- // Define the UrlsCollection that contains UrlsConfigElement elements.
- public class UrlsCollection : ConfigurationElementCollection
- {
- protected override ConfigurationElement CreateNewElement()
- {
- return new UrlConfigElement();
- }
- protected override Object GetElementKey(ConfigurationElement element)
- {
- return ((UrlConfigElement)element).VirtualUrl;
- }
- public UrlConfigElement this[int index]
- {
- get
- {
- return (UrlConfigElement)BaseGet(index);
- }
- }
- }
- // Define the UrlConfigElement.
- public class UrlConfigElement : ConfigurationElement
- {
- [ConfigurationProperty("virtualUrl", IsRequired = true)]
- public string VirtualUrl
- {
- get
- {
- return (string)this["virtualUrl"];
- }
- set
- {
- this["virtualUrl"] = value;
- }
- }
- [ConfigurationProperty("destinationUrl", IsRequired = true)]
- public string DestinationUrl
- {
- get
- {
- return (string)this["destinationUrl"];
- }
- set
- {
- this["destinationUrl"] = value;
- }
- }
- }
- }
|