diff options
Diffstat (limited to 'samples/OpenIdProviderWebForms/Code')
-rw-r--r-- | samples/OpenIdProviderWebForms/Code/URLRewriter.cs | 63 | ||||
-rw-r--r-- | samples/OpenIdProviderWebForms/Code/Util.cs | 9 |
2 files changed, 6 insertions, 66 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 diff --git a/samples/OpenIdProviderWebForms/Code/Util.cs b/samples/OpenIdProviderWebForms/Code/Util.cs index 5cec951..84d3c63 100644 --- a/samples/OpenIdProviderWebForms/Code/Util.cs +++ b/samples/OpenIdProviderWebForms/Code/Util.cs @@ -24,11 +24,14 @@ namespace OpenIdProviderWebForms.Code { } public static Identifier BuildIdentityUrl() { - string username = HttpContext.Current.User.Identity.Name; + return BuildIdentityUrl(HttpContext.Current.User.Identity.Name); + } - // be sure to normalize case the way the user's identity page does. + public static Identifier BuildIdentityUrl(string username) { + // This sample Provider has a custom policy for normalizing URIs, which is that the whole + // path of the URI be lowercase except for the first letter of the username. username = username.Substring(0, 1).ToUpperInvariant() + username.Substring(1).ToLowerInvariant(); - return new Uri(HttpContext.Current.Request.Url, "/user/" + username); + return new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/user.aspx/" + username)); } internal static void ProcessAuthenticationChallenge(IAuthenticationRequest idrequest) { |