diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-18 07:43:26 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-18 07:43:26 -0800 |
commit | 9a6b0bdd2224f9754d2afad0dca303c3e89b9406 (patch) | |
tree | 00ba1bbb07e2f7f3c6e55162043a43281604b468 /src | |
parent | 73814c0e38e21f0f43e458a3f039ad40cf5683a1 (diff) | |
download | DotNetOpenAuth-9a6b0bdd2224f9754d2afad0dca303c3e89b9406.zip DotNetOpenAuth-9a6b0bdd2224f9754d2afad0dca303c3e89b9406.tar.gz DotNetOpenAuth-9a6b0bdd2224f9754d2afad0dca303c3e89b9406.tar.bz2 |
Fixed reporting while hosted in IIS so that isolated storage works.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/Reporting.cs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/DotNetOpenAuth/Reporting.cs b/src/DotNetOpenAuth/Reporting.cs index 1e2d136..5dfbc13 100644 --- a/src/DotNetOpenAuth/Reporting.cs +++ b/src/DotNetOpenAuth/Reporting.cs @@ -15,6 +15,7 @@ namespace DotNetOpenAuth { using System.Linq; using System.Net; using System.Reflection; + using System.Security; using System.Text; using System.Threading; using System.Web; @@ -91,7 +92,7 @@ namespace DotNetOpenAuth { Enabled = DotNetOpenAuthSection.Configuration.Reporting.Enabled; if (Enabled) { try { - file = IsolatedStorageFile.GetUserStoreForDomain(); + file = GetIsolatedStorage(); assemblyName = new AssemblyName(Assembly.GetExecutingAssembly().FullName); webRequestHandler = new StandardWebRequestHandler(); observations.Add(observedRequests = new PersistentHashSet(file, "requests.txt", 3)); @@ -292,6 +293,34 @@ namespace DotNetOpenAuth { } /// <summary> + /// Gets the isolated storage to use for reporting. + /// </summary> + /// <returns>An isolated storage location appropriate for our host.</returns> + private static IsolatedStorageFile GetIsolatedStorage() { + Contract.Ensures(Contract.Result<IsolatedStorageFile>() != null); + + IsolatedStorageFile result = null; + + // We'll try for whatever storage location we can get, + // and not catch exceptions from the last attempt so that + // the overall failure is caught by our caller. + try { + // This works on Personal Web Server + result = IsolatedStorageFile.GetUserStoreForDomain(); + } catch (SecurityException) { + } catch (IsolatedStorageException) { + } + + // This works on IIS when full trust is granted. + if (result == null) { + result = IsolatedStorageFile.GetMachineStoreForDomain(); + } + + Logger.Library.InfoFormat("Reporting will use isolated storage with scope: {0}", result.Scope); + return result; + } + + /// <summary> /// A set of values that persist the set to disk. /// </summary> private class PersistentHashSet : IDisposable { |