找不到HttpContextBase命名空间 [英] HttpContextBase namespace could not be Found

查看:106
本文介绍了找不到HttpContextBase命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   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();

在asp.net核心中与HttpContextBase一起工作的任何帮助吗?上面是我的示例代码,正在努力创建购物车.

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.

推荐答案

ASP.NET Core中没有 HttpContextBase . HttpContext 已经是一个抽象类(请参见

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.

这篇关于找不到HttpContextBase命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆