Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

HttpContext.Session.GetString("string") I get a NullReferenceException

$
0
0

NullReferenceException

when it gets to this line:

 var stringId = context.Session.GetString("cart");

    public class Uno
    {
        private readonly HttpContext context;

        public Uno()
        {
        }

        public Uno(HttpContext _context)
        {
            context = _context;
        }
        public  string GetCartId()
        {
            string cartId = "";
            var stringId = context.Session.GetString("cart");
            if(stringId == null)
            {
                cartId = Guid.NewGuid().ToString();
                stringId = cartId;
            }
            else if(stringId != null)
            {
                cartId = stringId;
            }
            return cartId;
        }
    }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>