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
posted @ 2020-02-03 14:07  洛晨随风  阅读(365)  评论(0编辑  收藏