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 Core 中的 HttpContextBase 的解决有什么帮助吗?上面是我正在创建购物车的示例代码。
没有HttpContextBase
在 ASP.NET Core 中。HttpContext
已经是一个抽象类(参见here https://github.com/aspnet/HttpAbstractions/blob/release/2.2/src/Microsoft.AspNetCore.Http.Abstractions/HttpContext.cs#L16)其实施于DefaultHttpContext
(see GitHub https://github.com/aspnet/HttpAbstractions/blob/release/2.2/src/Microsoft.AspNetCore.Http/DefaultHttpContext.cs#L16)。只需使用HttpContext
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)