我有这条鳕鱼:
[Serializable]
public class testC
{
string sir;
public testC()
{
sir = string.Empty;
}
public string GetString
{
get { return sir; }
set { sir = value; }
}
}
public class cookieTest
{
testC test;
public cookieTest()
{
test = new testC();
}
public testC GetTestC
{
get
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["test"];
test = cookie["first"] as testC;
return test;
}
set
{
HttpCookie cookie = new HttpCookie("test");
cookie.Expires = DateTime.Now.AddHours(8);
cookie["first"] = value.ToString();
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
}
}
}
我得到这个错误
无法通过引用转换、装箱转换、拆箱转换、包装转换或空类型转换将类型“字符串”转换为“testC”
是否可以从 cookie 中获取对象?或者我必须将我的所有数据写入 cookie 以设置和获取所有数据并创建一个新对象来获取?