Hi there,
I want use cookie in my web project. I must serialize my classes. Although my code can seralize and create cookie for my some classes, it cant create cookie for serializable my class which has NonSerialized fields. This is my seralize and cookie code :
public static bool f_SetCookie(string _sCookieName, object _oCookieValue, DateTime _dtimeExpirationDate)
{
bool retval = true;
try
{
if (HttpContext.Current.Request[_sCookieName] != null)
{
HttpContext.Current.Request.Cookies.Remove(_sCookieName);
}
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, _oCookieValue);
byte[] bArr = ms.ToArray();
MemoryStream objStream = new MemoryStream();
DeflateStream objZS = new DeflateStream(objStream, CompressionMode.Compress);
objZS.Write(bArr, 0, bArr.Length);
objZS.Flush();
objZS.Close();
byte[] bytes = objStream.ToArray();
string sCookieVal = Convert.ToBase64String(bytes);
HttpCookie cook = new HttpCookie(_sCookieName);
cook.Value = sCookieVal;
cook.Expires = _dtimeExpirationDate;
HttpContext.Current.Response.Cookies.Add(cook);
}
catch
{
retval = false;
}
return retval;
}
How can create cookie for my class whic has nonseralized field? Thank you for your helps.