Skip to content

Commit

Permalink
A more description error when there's an attempt to login over HTTP c…
Browse files Browse the repository at this point in the history
…onnection, when HTTPS is required for cookies.
  • Loading branch information
napernik committed Mar 13, 2020
1 parent 8593d3f commit d2092c6
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ private static void StoreUsernameImpl(string userName, bool persistAcrossSession
cookie.HttpOnly = true;

var context = HttpContext.Current;
if (context != null && context.Request.IsSecureConnection)
if (context != null)
{
cookie.Secure = true;
if (context.Request.IsSecureConnection)
{
cookie.Secure = true;
}
else if (cookie.Secure)
{
throw new InvalidOperationException(
"A login attempt over a not secure connection, when system.web/httpCookies/@requireSSL is set to 'true'. " +
"Either secure connection should be required for console login, or SSL should not be required for cookies.");
}
}

if (persistAcrossSessions)
Expand Down

0 comments on commit d2092c6

Please sign in to comment.