diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-02-01 13:18:33 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2009-02-01 13:18:33 -0800 |
commit | e6512c223cb078b5f2fd4ea4abb28810ecca8c47 (patch) | |
tree | bb9dbea5e485a9a2c6aca44308659577333fba26 /samples/OpenIdProviderWebForms/Global.asax.cs | |
parent | e865ec7da293496d6c2e67039b86c4ef9ded5a6c (diff) | |
download | DotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.zip DotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.tar.gz DotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.tar.bz2 |
Renamed OpenID Provider sample directory to match project name.
Diffstat (limited to 'samples/OpenIdProviderWebForms/Global.asax.cs')
-rw-r--r-- | samples/OpenIdProviderWebForms/Global.asax.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/samples/OpenIdProviderWebForms/Global.asax.cs b/samples/OpenIdProviderWebForms/Global.asax.cs new file mode 100644 index 0000000..89d9268 --- /dev/null +++ b/samples/OpenIdProviderWebForms/Global.asax.cs @@ -0,0 +1,82 @@ +//----------------------------------------------------------------------- +// <copyright file="Global.asax.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace OpenIdProviderWebForms { + using System; + using System.Collections.Specialized; + using System.IO; + using System.Text; + using System.Web; + using OpenIdProviderWebForms.Code; + + public class Global : System.Web.HttpApplication { + public static log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(Global)); + + internal static StringBuilder LogMessages = new StringBuilder(); + + public static string ToString(NameValueCollection collection) { + using (StringWriter sw = new StringWriter()) { + foreach (string key in collection.Keys) { + if (key.StartsWith("__")) { + continue; // skip + } + sw.WriteLine("{0} = '{1}'", key, collection[key]); + } + return sw.ToString(); + } + } + + protected void Application_Start(object sender, EventArgs e) { + log4net.Config.XmlConfigurator.Configure(); + Logger.Info("Sample starting..."); + } + + protected void Application_End(object sender, EventArgs e) { + Logger.Info("Sample shutting down..."); + + // this would be automatic, but in partial trust scenarios it is not. + log4net.LogManager.Shutdown(); + } + + protected void Application_BeginRequest(object sender, EventArgs e) { + /* + * The URLRewriter was taken from http://www.codeproject.com/aspnet/URLRewriter.asp and modified slightly. + * It will read the config section called 'urlrewrites' from web.config and process each rule + * The rules are set of url transformations defined using regular expressions with support for substitutions (the ability to extract regex-matched portions of a string). + * There is only one rule currenty defined. It rewrites urls like: user/john ->user.aspx?username=john + */ + //// System.Diagnostics.Debugger.Launch(); + Logger.DebugFormat("Processing {0} on {1} ", this.Request.HttpMethod, this.stripQueryString(this.Request.Url)); + if (Request.QueryString.Count > 0) { + Logger.DebugFormat("Querystring follows: \n{0}", ToString(Request.QueryString)); + } + if (Request.Form.Count > 0) { + Logger.DebugFormat("Posted form follows: \n{0}", ToString(Request.Form)); + } + + URLRewriter.Process(); + } + + protected void Application_AuthenticateRequest(object sender, EventArgs e) { + Logger.DebugFormat("User {0} authenticated.", HttpContext.Current.User != null ? "IS" : "is NOT"); + } + + protected void Application_EndRequest(object sender, EventArgs e) { + } + + protected void Application_Error(object sender, EventArgs e) { + Logger.ErrorFormat( + "An unhandled exception was raised. Details follow: {0}", + HttpContext.Current.Server.GetLastError()); + } + + private string stripQueryString(Uri uri) { + UriBuilder builder = new UriBuilder(uri); + builder.Query = null; + return builder.ToString(); + } + } +}
\ No newline at end of file |