[英]Cookie not showing up on localHost website
我一直在試圖弄清為什么我的Cookie無法顯示在網站上,這是我的代碼:
public static class UpdateCookieHelper
{
public const string COOKIE_ACCESSOR = "TurboGroup";
public static void SetCookie(Group aModel)
{
HttpCookie _Cookie = new HttpCookie(COOKIE_ACCESSOR);
if (aModel == null)
_Cookie.Value = String.Empty;
else
_Cookie.Value = HttpUtility.UrlEncode(JsonConvert.SerializeObject(aModel));
if (HttpContext.Current.Request.Cookies[COOKIE_ACCESSOR] == null)
HttpContext.Current.Response.Cookies.Add(_Cookie);
else
HttpContext.Current.Response.Cookies.Set(_Cookie);
}
}
這是我如何調用該函數:
UpdateCookieHelper.SetCookie(_Group);
運行調試時,它會獲取所需的信息,但是在網站上,我看不到Cookie,因此我的getCookie()函數始終為null。
有人有主意嗎?
答案是編碼。 無需使用JSON。 現在工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.