To access this feature, it is important to configure your cookie authentication settings. This can be done by allowing explicit access in the cookie authentication options. In most cases, you will need to modify the CookieHttpOnly
setting to false
within the CookieAuthenticationOptions
object. Typically, you can find and edit this configuration in the Startup.Auth.cs file located in the App_Start folder of your project. When working with a new MVC 5 application based on the default template, the configuration will resemble the following:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieHttpOnly = false, // Enabling JavaScript access requires this setting
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
});