Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Set a user variable (or cookie, don't use session) which is used throughout the site to represent user in ASP.NET
Posted

1 solution

Hello Sailaja,

you can code like this,

C#
//add a username Cookie
Response.Cookies["userName"].Value = "Username";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(10);
//Can Limit a cookie to a certain Domain
Response.Cookies["domain"].Domain = "Codeproject.com";
//request a username cookie
if(Request.Cookies["userName"] != null)
   lblUserName.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);


Note:No sensitive information should be stored in a cookie.

All the Best:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900