0
我有一个ASP.Net的Core 2项目,我设置的所有验证配置ASP.NET MVC应用程序标识不与ASP.NET核心共享2
在ASP.Net的Core 2 Preview2 \ Start.cs中
var protectionProvider = DataProtectionProvider.Create(new DirectoryInfo(@"C:\SharedFolder"));
var dataProtector = protectionProvider.CreateProtector(
"CookieAuthenticationMiddleware",
"Cookie",
"v2");
var ticketFormat = new TicketDataFormat(dataProtector);
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddAuthentication(o =>{
o.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
services.ConfigureApplicationCookie(c => {
c.CookieName = "myapplication";
c.ExpireTimeSpan = TimeSpan.FromDays(3);
c.CookieSecure = CookieSecurePolicy.None;
c.SlidingExpiration = true;
});
在ASP.Net MVC4 \
ConfigureAuth
功能:
var protectionProvider = DataProtectionProvider.Create(new DirectoryInfo(@"C:\SharedFolder"));
var dataProtector = protectionProvider.CreateProtector(
"CookieAuthenticationMiddleware",
"Cookie",
"v2");
var ticketFormat = new AspNetTicketDataFormat(new DataProtectorShim(dataProtector));
app.UseCookieAuthentication(new CookieAuthenticationOptions{
AuthenticationType = "Cookie",
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
CookieName = "myapplication",
CookieDomain = "localhost",
TicketDataFormat = ticketFormat,
CookieManager = new ChunkingCookieManager()
});
份额饼干可以正常运行我Asp.Net的Core2项目设置的cookie和我读t形式MVC项目和反之亦然正确,当我检查用户IsAuthenticated总是在MVC项目中得到错误。
我如何在MVC项目中获得用户身份?任何帮助都比欢迎,提前谢谢。