我有一个ASP.net应用程序,它使用cookie来存储用户选择的语言.一切正常,除非我在localhost上.用127.0.0.1替换localhost使它再次工作......为什么?
我看到了对file://的预期限制,但我实际上找不到对localhost的预期限制的任何引用.
我无法理解的是为什么ASP.net会话(ASP.NET_SessionId)和ASP.net表单身份验证Cookie(.FSAUTHSSO)是为localhost域正确设置的,但我的cookie不是......为什么?!
我已经google了很多,没有任何作用:
那有什么关系呢?:)
为什么ASP.net cookie可以设置而我的不会?有什么不同?
最后一件事就是提到这也发生在IE上,但在FF上工作正常.
谢谢!
亚历克斯
我已启用使用Cookie的身份验证:
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WebBasic.Core.Controllers;
namespace WebBasic.Core
{
  public class Startup
  {
    public void ConfigureServices(IServiceCollection services)
    {
      services.AddMvc();
      services.AddAuthentication().AddCookie(AuthController.AuthControllerAuthId);
      services.AddAuthorization(options => { options.AddPolicy("IsFoo", policy => policy.RequireClaim("FooType")); });
    }
    public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
    {
      app.UseMvc();
      app.UseAuthentication();
    }
  }
}
...并创建了通用视图来测试声明:
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
namespace WebBasic.Core.Controllers
{
  [Route("/api/[controller]/[action]")]
  public class AuthController : Controller
  {
    public const string AuthControllerAuthId = "AuthControllerAuthId";
    public IActionResult Test()
    {
      var claims = …