summaryrefslogtreecommitdiffstats
path: root/samples/OAuthAuthorizationServer
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-05-06 22:24:50 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2011-05-06 22:24:50 -0700
commitd7e07694026888ae40254ee8468e40afe0ffee56 (patch)
treea10fdfb539b8481eea7d3400e70b85c6e8d6aa43 /samples/OAuthAuthorizationServer
parent0d17e6bbbd119520269716fb5de7db36a1a28683 (diff)
parent031ef0e5f8111bc5e1c157b8159d2b9e28b4eda3 (diff)
downloadDotNetOpenAuth-d7e07694026888ae40254ee8468e40afe0ffee56.zip
DotNetOpenAuth-d7e07694026888ae40254ee8468e40afe0ffee56.tar.gz
DotNetOpenAuth-d7e07694026888ae40254ee8468e40afe0ffee56.tar.bz2
Merge branch 'v3.4' into oauth2
Conflicts: samples/OAuthServiceProvider/Code/Global.cs src/DotNetOpenAuth/Configuration/DotNetOpenAuth.xsd src/DotNetOpenAuth/DotNetOpenAuth.csproj src/DotNetOpenAuth/Messaging/Channel.cs src/version.txt
Diffstat (limited to 'samples/OAuthAuthorizationServer')
-rw-r--r--samples/OAuthAuthorizationServer/Global.asax.cs127
1 files changed, 68 insertions, 59 deletions
diff --git a/samples/OAuthAuthorizationServer/Global.asax.cs b/samples/OAuthAuthorizationServer/Global.asax.cs
index 97e0016..2c23ec0 100644
--- a/samples/OAuthAuthorizationServer/Global.asax.cs
+++ b/samples/OAuthAuthorizationServer/Global.asax.cs
@@ -15,56 +15,56 @@
/// Note: For instructions on enabling IIS6 or IIS7 classic mode,
/// visit http://go.microsoft.com/?LinkId=9394801
/// </remarks>
- public class MvcApplication : System.Web.HttpApplication {
- /// <summary>
- /// An application memory cache of recent log messages.
- /// </summary>
- public static StringBuilder LogMessages = new StringBuilder();
-
- /// <summary>
- /// The logger for this sample to use.
- /// </summary>
- public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.OAuthAuthorizationServer");
-
- public static DatabaseNonceStore NonceStore { get; set; }
-
- /// <summary>
- /// Gets the transaction-protected database connection for the current request.
- /// </summary>
- public static DataClassesDataContext DataContext {
- get {
- DataClassesDataContext dataContext = DataContextSimple;
- if (dataContext == null) {
- dataContext = new DataClassesDataContext();
- dataContext.Connection.Open();
- dataContext.Transaction = dataContext.Connection.BeginTransaction();
- DataContextSimple = dataContext;
- }
-
- return dataContext;
- }
- }
-
- public static User LoggedInUser {
- get { return DataContext.Users.SingleOrDefault(user => user.OpenIDClaimedIdentifier == HttpContext.Current.User.Identity.Name); }
- }
-
- private static DataClassesDataContext DataContextSimple {
- get {
- if (HttpContext.Current != null) {
- return HttpContext.Current.Items["DataContext"] as DataClassesDataContext;
- } else {
- throw new InvalidOperationException();
- }
- }
-
- set {
- if (HttpContext.Current != null) {
- HttpContext.Current.Items["DataContext"] = value;
- } else {
- throw new InvalidOperationException();
- }
- }
+ public class MvcApplication : System.Web.HttpApplication {
+ /// <summary>
+ /// An application memory cache of recent log messages.
+ /// </summary>
+ public static StringBuilder LogMessages = new StringBuilder();
+
+ /// <summary>
+ /// The logger for this sample to use.
+ /// </summary>
+ public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.OAuthAuthorizationServer");
+
+ public static DatabaseNonceStore NonceStore { get; set; }
+
+ /// <summary>
+ /// Gets the transaction-protected database connection for the current request.
+ /// </summary>
+ public static DataClassesDataContext DataContext {
+ get {
+ DataClassesDataContext dataContext = DataContextSimple;
+ if (dataContext == null) {
+ dataContext = new DataClassesDataContext();
+ dataContext.Connection.Open();
+ dataContext.Transaction = dataContext.Connection.BeginTransaction();
+ DataContextSimple = dataContext;
+ }
+
+ return dataContext;
+ }
+ }
+
+ public static User LoggedInUser {
+ get { return DataContext.Users.SingleOrDefault(user => user.OpenIDClaimedIdentifier == HttpContext.Current.User.Identity.Name); }
+ }
+
+ private static DataClassesDataContext DataContextSimple {
+ get {
+ if (HttpContext.Current != null) {
+ return HttpContext.Current.Items["DataContext"] as DataClassesDataContext;
+ } else {
+ throw new InvalidOperationException();
+ }
+ }
+
+ set {
+ if (HttpContext.Current != null) {
+ HttpContext.Current.Items["DataContext"] = value;
+ } else {
+ throw new InvalidOperationException();
+ }
+ }
}
public static void RegisterRoutes(RouteCollection routes) {
@@ -96,19 +96,28 @@
protected void Application_Error(object sender, EventArgs e) {
Logger.Error("An unhandled exception occurred in ASP.NET processing: " + Server.GetLastError(), Server.GetLastError());
+
+ // In the event of an unhandled exception, reverse any changes that were made to the database to avoid any partial database updates.
+ var dataContext = DataContextSimple;
+ if (dataContext != null) {
+ dataContext.Transaction.Rollback();
+ dataContext.Connection.Close();
+ dataContext.Dispose();
+ DataContextSimple = null;
+ }
}
protected void Application_EndRequest(object sender, EventArgs e) {
CommitAndCloseDatabaseIfNecessary();
}
- private static void CommitAndCloseDatabaseIfNecessary() {
- var dataContext = DataContextSimple;
- if (dataContext != null) {
- dataContext.SubmitChanges();
- dataContext.Transaction.Commit();
- dataContext.Connection.Close();
- }
- }
- }
+ private static void CommitAndCloseDatabaseIfNecessary() {
+ var dataContext = DataContextSimple;
+ if (dataContext != null) {
+ dataContext.SubmitChanges();
+ dataContext.Transaction.Commit();
+ dataContext.Connection.Close();
+ }
+ }
+ }
} \ No newline at end of file