We are using Request.Cookies for get the values of cookies and the Respone.Cookies are use to add the cookies.
In the below example, used to Respone.Cookies for create/ add new cookies. i.e.
In the below example, used to Respone.Cookies for create/ add new cookies. i.e.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
| //This method id used to Create the cookies and assign the values in cookies. private static void SetCookies(UserSession userSession) { new HttpCookie( "GlobalCookieName " ); cookie.Values[ "CompanyID" ] = Convert.ToString(userSession.CompanyID); cookie.Values[ "TenantId" ] = userSession.CompanyName; cookie.Values[ "EmailID" ] = userSession.EmailID; cookie.Values[ "UserType" ] = Convert.ToString(userSession.UserType); cookie.Expires = DateTime.Now.AddDays(365); HttpContext.Current.Response.Cookies.Add(cookie); } |
//This method id used to Create the cookies and assign the values in cookies. private static void SetCookies(UserSession userSession) { HttpCookie cookie = HttpContext.Current.Request.Cookies["GlobalCookieName"] ?? new HttpCookie("GlobalCookieName "); cookie.Values["CompanyID"] = Convert.ToString(userSession.CompanyID); cookie.Values["TenantId"] = userSession.CompanyName; cookie.Values["EmailID"] = userSession.EmailID; cookie.Values["UserType"] = Convert.ToString(userSession.UserType); cookie.Expires = DateTime.Now.AddDays(365); HttpContext.Current.Response.Cookies.Add(cookie); }
1
2
3
4
5
6
7
8
9
| //This is the property class. public class UserSession { public string EmailID { get ; set ; } public int TenantID { get ; set ; } public int CompanyID { get ; set ; } public string UserType { get ; set ; } } |
//This is the property class. public class UserSession { public string EmailID { get; set; } public int TenantID { get; set; } public int CompanyID { get; set; } public string UserType { get; set; } }