![](/img/trans.png)
[英]How can I drop bower and use npm for client-side in ASP.NET Core 1.0?
[英]Why I can't use HttpContext or HttpCookie? (Asp.Net Core 1.0)
為什么不能使用HttpContext
或HttpCookie
? 有特殊用途嗎?
我的實際用法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
我的名稱空間:
namespace eCoffee.Main
我的課+方法:
public class AppRunCookie
{
public static string CookieName { get; set; }
public static string Key { get; set; }
public AppRunCookie(string key)
{
CookieName = "MyCookie_" + key;
}
public static void SetCookie(string key, int cookieExpireDate = 30)
{
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie["Key"] = key;
myCookie.Expires = DateTime.Now.AddDays(cookieExpireDate);
HttpContext.Current.Response.Cookies.Add(myCookie);
}
public string GetCookie()
{
HttpCookie myCookie = HttpContext.Current.Request.Cookies[CookieName];
if (myCookie != null)
{
string key = Convert.ToString(myCookie.Values["Key"]);
return key;
}
return "";
}
}
我做錯了什么?
HttpContext
和HttpCookie
的命名空間是System.Web
,它是System.Web.dll
庫的一部分。
右鍵單擊項目References
然后選擇Add References...
在新打開的窗口中點擊Assemblies
,然后搜索(通過在右上角的搜索欄)為System.Web
。
然后,您應該可以通過以下方式使用它
using System.Web;
所以大家好
我找到了解決方案,請嘗試使用此精彩的博客文章。
注意:請確保您通過nuget安裝程序安裝了nuget-packages,並且還確保選中了“ include prerelease”復選框。
希望我的帖子對您有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.