该楼层疑似违规已被系统折叠隐藏此楼查看此楼
问题五
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()
如果觉得《计算机专业问题解答 计算机科学专业的编程问题 解答 有问必答》对你有帮助,请点赞、收藏,并留下你的观点哦!