最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS get cookie ASP.NET Core Identity - Stack Overflow

programmeradmin0浏览0评论

For my ASP.NET Core project with using Identity I have some cookies. And on client-side I want to check if user is logged in. I'm trying to get .AspNetCore.Identity.Application cookie, but there is no such cookie in js document.cookie. Can I get ASP.NET Core Identity cookie from js? Or what's the best way to check if user is logged in with using cookie?

For my ASP.NET Core project with using Identity I have some cookies. And on client-side I want to check if user is logged in. I'm trying to get .AspNetCore.Identity.Application cookie, but there is no such cookie in js document.cookie. Can I get ASP.NET Core Identity cookie from js? Or what's the best way to check if user is logged in with using cookie?

Share Improve this question asked Dec 23, 2016 at 9:25 A. GladkiyA. Gladkiy 3,4507 gold badges44 silver badges90 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

It looks as if ASP.NET has set httponly flag for your cookie. In this case it will not be accessable from javascript.

No, you can't from js but if you just want to check if the cookie exists or not then you can check this in razor code and pass it to any variable and then pass this variable to the javascript variable.

  @{
        var isLoggedIn = Context.Request.Cookies.ContainsKey(".AspNetCore.Identity.Application");
    }

<script>
var loggedIn = '@isLoggedIn'
</script>
发布评论

评论列表(0)

  1. 暂无评论