c# – 无法找到HttpContextBase名称空间
发布时间:2020-12-15 06:18:32 所属栏目:百科 来源:网络整理
导读: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 { // Gener
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的任何帮助吗?上面是我的示例代码我正在努力创建一个购物车. 解决方法
ASP.NET Core中没有HttpContextBase. HttpContext已经是一个抽象类(见
here),它在DefaultHttpContext中实现(见
GitHub).只需使用HttpContext.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |