diff --git a/src/Nancy/Diagnostics/DiagnosticsConfiguration.cs b/src/Nancy/Diagnostics/DiagnosticsConfiguration.cs
index 63fcff1aff..e86fa05fd6 100644
--- a/src/Nancy/Diagnostics/DiagnosticsConfiguration.cs
+++ b/src/Nancy/Diagnostics/DiagnosticsConfiguration.cs
@@ -8,20 +8,40 @@
public class DiagnosticsConfiguration
{
- public DiagnosticsConfiguration() : this(CryptographyConfiguration.Default)
+ ///
+ /// Initializes a new instance of the class,
+ /// using the cryptographic
+ /// configuration.
+ ///
+ public DiagnosticsConfiguration()
+ : this(CryptographyConfiguration.Default)
{
}
+ ///
+ /// Initializes a new instance of the class,
+ /// using the cryptographic
+ /// configuration.
+ ///
+ /// The to use with diagnostics.
public DiagnosticsConfiguration(CryptographyConfiguration cryptographyConfiguration)
{
+ this.CookieName = "__ncd";
this.CryptographyConfiguration = cryptographyConfiguration;
this.Path = "/_Nancy";
+ this.Timeout = 15;
}
///
- /// Gets or sets the path that the diagnostics dashboard will be accessible on.
+ /// Gets or sets the name of the cookie used by the diagnostics dashboard.
///
- public string Path { get; set; }
+ /// The default is __ncd
+ public string CookieName { get; set; }
+
+ ///
+ /// Gets or sets the cryptography config to use for securing the diagnostics dashboard
+ ///
+ public CryptographyConfiguration CryptographyConfiguration { get; set; }
///
/// Gets or sets password for accessing the diagnostics screen.
@@ -30,9 +50,16 @@ public DiagnosticsConfiguration(CryptographyConfiguration cryptographyConfigurat
public string Password { get; set; }
///
- /// Gets or sets the cryptography config to use for securing the diagnostics dashboard
+ /// Gets or sets the path that the diagnostics dashboard will be accessible on.
///
- public CryptographyConfiguration CryptographyConfiguration { get; set; }
+ /// The default is /_Nancy
+ public string Path { get; set; }
+
+ ///
+ /// The number of minutes that you stay logged into the diagnostics dashboard.
+ ///
+ /// The default is 15 minutes.
+ public int Timeout { get; set; }
///
/// Gets a value indicating whether the configuration is valid
diff --git a/src/Nancy/Diagnostics/DiagnosticsHook.cs b/src/Nancy/Diagnostics/DiagnosticsHook.cs
index 7e8358f542..d6e577751b 100644
--- a/src/Nancy/Diagnostics/DiagnosticsHook.cs
+++ b/src/Nancy/Diagnostics/DiagnosticsHook.cs
@@ -17,9 +17,6 @@ public static class DiagnosticsHook
{
private const string PipelineKey = "__Diagnostics";
- private const string DiagsCookieName = "__ncd";
- private const int DiagnosticsSessionTimeoutMinutes = 15;
-
public static void Enable(DiagnosticsConfiguration diagnosticsConfiguration, IPipelines pipelines, IEnumerable providers, IRootPathProvider rootPathProvider, IEnumerable serializers, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable responseProcessors)
{
var keyGenerator = new DefaultModuleKeyGenerator();
@@ -115,7 +112,7 @@ private static Response ExecuteDiagnostics(NancyContext ctx, IRouteResolver rout
var view = GetDiagnosticsLoginView(ctx);
view.AddCookie(
- new NancyCookie(DiagsCookieName, String.Empty, true) { Expires = DateTime.Now.AddDays(-1) });
+ new NancyCookie(diagnosticsConfiguration.CookieName, String.Empty, true) { Expires = DateTime.Now.AddDays(-1) });
return view;
}
@@ -154,14 +151,14 @@ private static void AddUpdateSessionCookie(DiagnosticsSession session, NancyCont
return;
}
- session.Expiry = DateTime.Now.AddMinutes(DiagnosticsSessionTimeoutMinutes);
+ session.Expiry = DateTime.Now.AddMinutes(diagnosticsConfiguration.Timeout);
var serializedSession = serializer.Serialize(session);
var encryptedSession = diagnosticsConfiguration.CryptographyConfiguration.EncryptionProvider.Encrypt(serializedSession);
var hmacBytes = diagnosticsConfiguration.CryptographyConfiguration.HmacProvider.GenerateHmac(encryptedSession);
var hmacString = Convert.ToBase64String(hmacBytes);
- var cookie = new NancyCookie(DiagsCookieName, String.Format("{1}{0}", encryptedSession, hmacString), true);
+ var cookie = new NancyCookie(diagnosticsConfiguration.CookieName, String.Format("{1}{0}", encryptedSession, hmacString), true);
context.Response.AddCookie(cookie);
}
@@ -178,12 +175,12 @@ private static DiagnosticsSession GetSession(NancyContext context, DiagnosticsCo
return ProcessLogin(context, diagnosticsConfiguration, serializer);
}
- if (!context.Request.Cookies.ContainsKey(DiagsCookieName))
+ if (!context.Request.Cookies.ContainsKey(diagnosticsConfiguration.CookieName))
{
return null;
}
- var encryptedValue = HttpUtility.UrlDecode(context.Request.Cookies[DiagsCookieName]);
+ var encryptedValue = HttpUtility.UrlDecode(context.Request.Cookies[diagnosticsConfiguration.CookieName]);
var hmacStringLength = Base64Helpers.GetBase64Length(diagnosticsConfiguration.CryptographyConfiguration.HmacProvider.HmacLength);
var encryptedSession = encryptedValue.Substring(hmacStringLength);
var hmacString = encryptedValue.Substring(0, hmacStringLength);
@@ -230,7 +227,7 @@ private static DiagnosticsSession ProcessLogin(NancyContext context, Diagnostics
{
Hash = hash,
Salt = salt,
- Expiry = DateTime.Now.AddMinutes(DiagnosticsSessionTimeoutMinutes),
+ Expiry = DateTime.Now.AddMinutes(diagnosticsConfiguration.Timeout)
};
return session;
@@ -239,7 +236,7 @@ private static DiagnosticsSession ProcessLogin(NancyContext context, Diagnostics
private static bool IsLoginRequest(NancyContext context, DiagnosticsConfiguration diagnosticsConfiguration)
{
return context.Request.Method == "POST" &&
- context.Request.Path == string.Concat(diagnosticsConfiguration.Path);
+ context.Request.Path == diagnosticsConfiguration.Path;
}
private static void ExecuteRoutePreReq(NancyContext context, Func resolveResultPreReq)