netcore 设置 cookie的httponly写法

全局设置:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

     //app.UseCookiePolicy(new CookiePolicyOptions 
            //{ 
            //    HttpOnly= HttpOnlyPolicy.Always
            //});

}

个别设置:

 HttpContext.Response.Cookies.Append("user", "zsf",new CookieOptions 
            { 
                HttpOnly= true,
                //Secure = true
            });
            HttpContext.Response.Cookies.Append("user2", "lssss", new CookieOptions
            {
                HttpOnly = false,
               // Secure=true
            });

其中 如果只希望通过https来获取cookie就设置 

Secure为true

你可能感兴趣的:(netcore 设置 cookie的httponly写法)