Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read cookie expiration in dot net core?

I see you can set the expiration using CookieOptions when appending a new cookie to the response. However, HttpContext.Request.Cookies returns an IRequestCookieCollection, which only seems to give you key/value pairs.

Is there a way to read the CookieOptions (specifically the Expiration) for request cookies?

I'm using .Net Core (1.0.0-preview2-003131)

NOTE: I need to read the expiration of an arbitrary cookie in request processing, not the expiration of the framework generated auth cookie.

like image 487
me_online Avatar asked Feb 04 '17 20:02

me_online


People also ask

How to access cookies in core ASP NET?

In ASP.NET, we can access cookies using httpcontext.current but in ASP.NET Core, there is no htttpcontext.currently. In ASP.NET Core, everything is decoupled and modular.

How to set expiry date of cookie in ASP NET?

//Set the Expiry date of the Cookie. //Create a Cookie with a suitable Key and add the Cookie to Browser. //Fetch the Cookie value using its Key. //Delete the Cookie from Browser. The View consists of an HTML Form with following ASP.Net Tag Helpers attributes. asp-controller – Name of the Controller. In this case the name is Home.

What happens when a cookie expires?

If the cookie is expired, it is not sent to the server to extract any information. With ASP.Net Core Identity, you don't have much control over that. That leaves you to using Cookie Middleware.

What is the difference between core identity and cookie-based authentication?

ASP.NET Core Identity is a complete, full-featured authentication provider for creating and maintaining logins. However, a cookie-based authentication authentication provider without ASP.NET Core Identity can be used.


1 Answers

No, HTTP does not include any details about cookies sent on requests, only their name and value. The auth cookie workaround only works because the expiration is also embedded in the value.

like image 161
Tratcher Avatar answered Sep 21 '22 09:09

Tratcher