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?以上是我正在創建購物車的示例代碼。HttpContextBase命名空間無法找到
您可以使用HttpContextBase abstractContext = new System.Web.HttpContextWrapper(context); – Tomato32
@ Tomato32 ASP.NET Core中不再有'System.Web' – Tseng
你是否在控制器之外執行此操作? – Coemgen