Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContextBase namespace could not be found

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 the work around with HttpContextBase in asp.net core? above is my sample code am working on to create a shopping cart.

like image 377
ABEL MASILA Avatar asked Jun 27 '17 08:06

ABEL MASILA


Video Answer


1 Answers

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

like image 135
Tseng Avatar answered Sep 28 '22 21:09

Tseng