Could not find HttpContextBase namespace

public string GetCartId(HttpContextBase context) { if (context.Session[CartSessionKey] == null) { if (!string.IsNullOrWhiteSpace(context.User.Identity.Name)) { context.Session[CartSessionKey] = context.User.Identity.Name; } else { // Generate a new random GUID using System.Guid class Guid tempCartId = Guid.NewGuid(); // Send tempCartId back to client as a cookie context.Session[CartSessionKey] = tempCartId.ToString(); } } return context.Session[CartSessionKey].ToString(); 

Any help on working with HttpContextBase in asp.net core? above, my sample code is working on creating a shopping cart.

+6
source share
2 answers

There is no HttpContextBase in ASP.NET Core. HttpContext already an abstract class (see here ), which is implemented in DefaultHttpContext (see GitHub ). Just use HttpContext .

+13
source

I had to change as below

 public string GetCartId(HttpContext context) { if (context.Session.GetString(CartSessionKey) == null) { if (!string.IsNullOrWhiteSpace(context.User.Identity.Name)) { context.Session.SetString(CartSessionKey, context.User.Identity.Name); } else { var tempCartId = Guid.NewGuid(); context.Session.SetString(CartSessionKey, tempCartId.ToString()); } } return context.Session.GetString(CartSessionKey); } 

I can help someone :)

0
source

Source: https://habr.com/ru/post/1269247/


All Articles