How to access cookie asp.net core

tocoolforscool
var claims = new[]
{
  new Claim("UserID", user.ID.ToString()),
  new Claim(ClaimTypes.Role, "pioneer")
};

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

await HttpContext.Authentication.SignInAsync("Cookies", principal);

This is the cookie that I'm creating and using to sign in as per instruction from this tutorial: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie

The cookie is being created, but I don't know how to access the cookie or the data inside of it to get the user.ID value.

travis.js

Once you sign via HttpContext.Authentication.SignInAsync, you should be able to access the User property in your controllers (it is part of ControllerBase), or HttpContext.User.

This User is a ClaimsPrincipal object that is created from the cookie automatically.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

access cookie in _Layout.cshtml in ASP.NET Core

From Java

How to set SameSite cookie attribute to explicit None ASP NET Core

From Dev

How to set the cookie validateInterval in ASP.NET Core?

From Dev

How to set never-expiring cookie in ASP.NET Core?

From Dev

How to implement Permission Based Access Control with Asp.Net Core

From Dev

How to access session from a view in ASP .NET Core MVC 1.0

From Dev

How to access the Session in ASP.NET Core via static variable?

From Dev

How to access Asp.net Core DI Container from Class

From Dev

How can I check for a response cookie in Asp.net Core MVC (aka Asp.Net 5 RC1)?

From Dev

ASP. Net Core 2.2 with cookie authentication: how to avoid page redirect when not authorized for API only controllers

From Dev

ASP.NET Core .NET Framework testing with cookie

From Java

Access the current HttpContext in ASP.NET Core

From Dev

Access Denied in Asp .Net Core by Claims Authorization

From Dev

Asp.Net - How to expire Cookie

From Dev

How to fetch cookie with name in asp.net

From Dev

Replace value in cookie ASP.NET Core 1.0

From Dev

ASP.NET Core MVC: setting expiration of identity cookie

From Dev

Using the Authorize Attribute with Custom Cookie Authentication in ASP.NET Core

From Dev

ASP.NET Core Identity 3 Cookie timeout

From Dev

ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

From Dev

JS get cookie ASP.NET Core Identity

From Dev

Rename TwoFactorUserId cookie in asp.net core 2.1

From Java

How do I access Configuration in any class in ASP.NET Core?

From Dev

How do I access DataContext from another class in ASP.NET Core?

From Dev

asp.net core 2.0 Entity Framework how to access user profile

From Dev

How can I access MongoDb in Asp.Net Core with a Username and Password?

From Dev

Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

From Dev

Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

From Java

Access environment name in Program.Main in ASP.NET Core

Related Related

  1. 1

    access cookie in _Layout.cshtml in ASP.NET Core

  2. 2

    How to set SameSite cookie attribute to explicit None ASP NET Core

  3. 3

    How to set the cookie validateInterval in ASP.NET Core?

  4. 4

    How to set never-expiring cookie in ASP.NET Core?

  5. 5

    How to implement Permission Based Access Control with Asp.Net Core

  6. 6

    How to access session from a view in ASP .NET Core MVC 1.0

  7. 7

    How to access the Session in ASP.NET Core via static variable?

  8. 8

    How to access Asp.net Core DI Container from Class

  9. 9

    How can I check for a response cookie in Asp.net Core MVC (aka Asp.Net 5 RC1)?

  10. 10

    ASP. Net Core 2.2 with cookie authentication: how to avoid page redirect when not authorized for API only controllers

  11. 11

    ASP.NET Core .NET Framework testing with cookie

  12. 12

    Access the current HttpContext in ASP.NET Core

  13. 13

    Access Denied in Asp .Net Core by Claims Authorization

  14. 14

    Asp.Net - How to expire Cookie

  15. 15

    How to fetch cookie with name in asp.net

  16. 16

    Replace value in cookie ASP.NET Core 1.0

  17. 17

    ASP.NET Core MVC: setting expiration of identity cookie

  18. 18

    Using the Authorize Attribute with Custom Cookie Authentication in ASP.NET Core

  19. 19

    ASP.NET Core Identity 3 Cookie timeout

  20. 20

    ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

  21. 21

    JS get cookie ASP.NET Core Identity

  22. 22

    Rename TwoFactorUserId cookie in asp.net core 2.1

  23. 23

    How do I access Configuration in any class in ASP.NET Core?

  24. 24

    How do I access DataContext from another class in ASP.NET Core?

  25. 25

    asp.net core 2.0 Entity Framework how to access user profile

  26. 26

    How can I access MongoDb in Asp.Net Core with a Username and Password?

  27. 27

    Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

  28. 28

    Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

  29. 29

    Access environment name in Program.Main in ASP.NET Core

HotTag

Archive