summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdProviderWebForms/Code/URLRewriter.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-03 17:00:05 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-03 17:00:05 -0700
commit8254a5ca1ced42181eb33e1282cfab5e429b0243 (patch)
tree7efd0efb5d555d57aec6eb9059a50a59eceb98b7 /samples/OpenIdProviderWebForms/Code/URLRewriter.cs
parenta124b5a041853c0d9f52244f43740c94bd6f4f3c (diff)
parent22873cc61615aaa01734857b0567e4878b2e325c (diff)
downloadDotNetOpenAuth-8254a5ca1ced42181eb33e1282cfab5e429b0243.zip
DotNetOpenAuth-8254a5ca1ced42181eb33e1282cfab5e429b0243.tar.gz
DotNetOpenAuth-8254a5ca1ced42181eb33e1282cfab5e429b0243.tar.bz2
Merge branch 'v3.0' into master
Diffstat (limited to 'samples/OpenIdProviderWebForms/Code/URLRewriter.cs')
-rw-r--r--samples/OpenIdProviderWebForms/Code/URLRewriter.cs63
1 files changed, 0 insertions, 63 deletions
diff --git a/samples/OpenIdProviderWebForms/Code/URLRewriter.cs b/samples/OpenIdProviderWebForms/Code/URLRewriter.cs
deleted file mode 100644
index be65e0a..0000000
--- a/samples/OpenIdProviderWebForms/Code/URLRewriter.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace OpenIdProviderWebForms.Code {
- using System.Configuration;
- using System.Diagnostics;
- using System.Text.RegularExpressions;
- using System.Web;
- using System.Xml;
-
- // nicked from http://www.codeproject.com/aspnet/URLRewriter.asp
- public class URLRewriter : IConfigurationSectionHandler {
- public static log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
-
- protected XmlNode rules = null;
-
- protected URLRewriter() {
- }
-
- public static void Process() {
- URLRewriter rewriter = (URLRewriter)ConfigurationManager.GetSection("urlrewrites");
-
- string subst = rewriter.GetSubstitution(HttpContext.Current.Request.Path);
-
- if (!string.IsNullOrEmpty(subst)) {
- Logger.InfoFormat("Rewriting url '{0}' to '{1}' ", HttpContext.Current.Request.Path, subst);
- HttpContext.Current.RewritePath(subst);
- }
- }
-
- public string GetSubstitution(string path) {
- foreach (XmlNode node in this.rules.SelectNodes("rule")) {
- // get the url and rewrite nodes
- XmlNode urlNode = node.SelectSingleNode("url");
- XmlNode rewriteNode = node.SelectSingleNode("rewrite");
-
- // check validity of the values
- if (urlNode == null || string.IsNullOrEmpty(urlNode.InnerText)
- || rewriteNode == null || string.IsNullOrEmpty(rewriteNode.InnerText)) {
- Logger.Warn("Invalid urlrewrites rule discovered in web.config file.");
- continue;
- }
-
- string oldValue = HttpContext.Current.Response.ApplyAppPathModifier(urlNode.InnerText);
-
- Regex reg = new Regex(oldValue, RegexOptions.IgnoreCase);
-
- // if match, return the substitution
- Match match = reg.Match(path);
- if (match.Success) {
- return reg.Replace(path, HttpContext.Current.Response.ApplyAppPathModifier(rewriteNode.InnerText));
- }
- }
-
- return null; // no rewrite
- }
-
- #region Implementation of IConfigurationSectionHandler
- public object Create(object parent, object configContext, XmlNode section) {
- this.rules = section;
-
- return this;
- }
- #endregion
- }
-} \ No newline at end of file