Update cookie name

This commit is contained in:
John Luo 2016-03-03 16:42:17 -08:00 committed by =
parent 91f44549ac
commit 91b955e080
3 changed files with 10 additions and 4 deletions

View File

@ -16,11 +16,17 @@ namespace Microsoft.AspNetCore.Antiforgery
private string _cookieName;
private string _formFieldName = AntiforgeryTokenFieldName;
/// <summary>
/// The default cookie prefix, which is ".AspNetCore.Antiforgery.".
/// </summary>
public static readonly string DefaultCookiePrefix = ".AspNetCore.Antiforgery.";
/// <summary>
/// Specifies the name of the cookie that is used by the antiforgery system.
/// </summary>
/// <remarks>
/// If an explicit name is not provided, the system will automatically generate a name.
/// If an explicit name is not provided, the system will automatically generate a
/// unique name that begins with <see cref="DefaultCookiePrefix"/>.
/// </remarks>
public string CookieName
{

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
if (options.CookieName == null)
{
var applicationId = dataProtectionOptions.ApplicationDiscriminator ?? string.Empty;
options.CookieName = ComputeCookieName(applicationId);
options.CookieName = AntiforgeryOptions.DefaultCookiePrefix + ComputeCookieName(applicationId);
}
}

View File

@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal
public class AntiforgeryOptionsSetupTest
{
[Theory]
[InlineData("HelloWorldApp", "tGmK82_ckDw")]
[InlineData("TodoCalendar", "7mK1hBEBwYs")]
[InlineData("HelloWorldApp", ".AspNetCore.Antiforgery.tGmK82_ckDw")]
[InlineData("TodoCalendar", ".AspNetCore.Antiforgery.7mK1hBEBwYs")]
public void AntiforgeryOptionsSetup_SetsDefaultCookieName_BasedOnApplicationId(
string applicationId,
string expectedCookieName)