该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
问题五
asp.net webApi 的cookie验证问题
net core MVC 基于cookie验证用户是否登录,但是在.net core WebAapi 中验证失败,请求是带有登录cookie的 但是User.Identity.IsAuthentication总是false
.net core webapi 是不是有什么不同呢?
配置都是正确的,
services.AddCors(options => { options.AddPolicy("AllowAllOrigin", builder => { builder.WithOrigins("http://xxx", "https://xxx") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); });});services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { ...... }); services.AddApiVersioning(option => { option.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0); option.AssumeDefaultVersionWhenUnspecified = true; option.ReportApiVersions = true; });///app.UseAuthentication();app.UseMvc()