Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cookies 在ASP.NET Core mvc 2.0中,使用无ASP.NET Core标识的Cookie身份验证共享在一个中创建的Cookie并在另一个中使用它? 应用1:_Cookies_Asp.net Core Mvc 2.0 - Fatal编程技术网

Cookies 在ASP.NET Core mvc 2.0中,使用无ASP.NET Core标识的Cookie身份验证共享在一个中创建的Cookie并在另一个中使用它? 应用1:

Cookies 在ASP.NET Core mvc 2.0中,使用无ASP.NET Core标识的Cookie身份验证共享在一个中创建的Cookie并在另一个中使用它? 应用1:,cookies,asp.net-core-mvc-2.0,Cookies,Asp.net Core Mvc 2.0,StartUp.cs public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) => { options.Cookie.Dom

StartUp.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();                
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
       options.Cookie.Domain = "localhost";
       options.Cookie.Name = "mycookie";
       options.Cookie.Path = "/";
       options.Cookie.HttpOnly = true;
       options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
   });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
var claims = new List<Claim>
{
    new Claim(ClaimTypes.Name, authUserNameBuilder.ToString())
};

var claimsIdentity = new ClaimsIdentity(claims,CookieAuthenticationDefaults.AuthenticationScheme);

await HttpContext.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme,
    new ClaimsPrincipal(claimsIdentity),
    new AuthenticationProperties{
        IsPersistent = false
    }
);
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
        options.Cookie.Domain = "localhost";
        options.Cookie.Name = "mycookie";
        options.Cookie.Path = "/";
        options.Cookie.HttpOnly = true;
        options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
    });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
foreach (var claims in HttpContext.User.Claims)
{
    Debug.WriteLine(claims.Value);
}
控制器.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();                
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
       options.Cookie.Domain = "localhost";
       options.Cookie.Name = "mycookie";
       options.Cookie.Path = "/";
       options.Cookie.HttpOnly = true;
       options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
   });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
var claims = new List<Claim>
{
    new Claim(ClaimTypes.Name, authUserNameBuilder.ToString())
};

var claimsIdentity = new ClaimsIdentity(claims,CookieAuthenticationDefaults.AuthenticationScheme);

await HttpContext.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme,
    new ClaimsPrincipal(claimsIdentity),
    new AuthenticationProperties{
        IsPersistent = false
    }
);
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
        options.Cookie.Domain = "localhost";
        options.Cookie.Name = "mycookie";
        options.Cookie.Path = "/";
        options.Cookie.HttpOnly = true;
        options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
    });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
foreach (var claims in HttpContext.User.Claims)
{
    Debug.WriteLine(claims.Value);
}
控制器.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();                
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
       options.Cookie.Domain = "localhost";
       options.Cookie.Name = "mycookie";
       options.Cookie.Path = "/";
       options.Cookie.HttpOnly = true;
       options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
   });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
var claims = new List<Claim>
{
    new Claim(ClaimTypes.Name, authUserNameBuilder.ToString())
};

var claimsIdentity = new ClaimsIdentity(claims,CookieAuthenticationDefaults.AuthenticationScheme);

await HttpContext.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme,
    new ClaimsPrincipal(claimsIdentity),
    new AuthenticationProperties{
        IsPersistent = false
    }
);
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie((options) =>
    {
        options.Cookie.Domain = "localhost";
        options.Cookie.Name = "mycookie";
        options.Cookie.Path = "/";
        options.Cookie.HttpOnly = true;
        options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
    });          
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{     
    app.UseAuthentication();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Accounts}/{action=Index}/{id?}");
    });
}
foreach (var claims in HttpContext.User.Claims)
{
    Debug.WriteLine(claims.Value);
}
在应用程序1的Controller.cs中,我使用Cookies身份验证创建Cookies,如代码所示

在应用程序1和应用程序2中,Startup.cs是相同的

在应用程序2的Controller.cs中,我尝试使用For循环获取应用程序1中创建的cookie,如代码所示

但我无法在应用程序1中创建的应用程序2中获取cookie。请建议

参考资料:

我指的是也许这会有所帮助-