Tutorials
Resources
Forum
Communities
Interview
Jobs
Projects
Offshore Development
Silverlight Tutorials
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Revenue Sharing
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
srinivasa reddy...
(17)
Babu Akkandi
(16)
Tejinder Singh ...
(10)
Last 7 Days
Appukuttan
(620)
Babu Akkandi
(453)
Tejinder Singh ...
(271)
more...
New Feature:
Community Sites
:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
Cookies in ASP.Net
Posted Date: 16 May 2008
Resource Type:
Articles
Category:
Web Applications
Author:
shakti singh tanwar
Member Level:
Diamond
Rating:
Points
: 10
Introduction
Cookies are small piece of information avilable on client that is used to keep vital information from server.Cookies are of two types:-
1.) Session Cookie:- The cookie lifetime is controlled by user’s session.When session expires cookie expires too.
2.) Persistent Cookie:-Like in dotnet spider if you select “Remember Me on this computer” checkbox while logging into the site then you don’t need to login again when you come back to the site after closing the browser without signing out.This is because the lifetime of persistent cookie is set by the user and not depedent on session lifetime.
Cookie are created using HTTPCOOKIE class and then added to the Response object’s Cookie cllection.Once you add a cookie to Response it will be available in Cookie’s collection of Request object on every subsequent request from the client.
Cookies are used vastly by sites for session management purposes and stores session id provided by the server after a successful login.Once logged in this session id is carried by Request back n forth to the server with every client request and thus helps the server identify an authenticated user.
Example
StringBuilder sb = new StringBuilder();
// Get cookie from the current request.
HttpCookie cookie = Request.Cookies.Get("DateCookie");
// Check if cookie exists in the current request.
if (cookie == null)
{
sb.Append("Cookie was not received from the client. ");
sb.Append("Creating cookie to add to the response.
");
// Create cookie.
cookie = new HttpCookie("DateCookie");
// Set value of cookie to current date time.
cookie.Value = DateTime.Now.ToString();
// Set cookie to expire in 10 minutes.
cookie.Expires = DateTime.Now.AddMinutes(10d);
// Insert the cookie in the current HttpResponse.
Response.Cookies.Add(cookie);
}
else
{
sb.Append("Cookie retrieved from client.
");
sb.Append("Cookie Name: " + cookie.Name + "
");
sb.Append("Cookie Value: " + cookie.Value + "
");
sb.Append("Cookie Expiration Date: " +
cookie.Expires.ToString() + "
");
}
string cookieText = sb.ToString();
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
List of functions in Javascript Math class
Previous Resource:
Managing Database Connections using ADO.NET
Return to Discussion Resource Index
Post New Resource
Category:
Web Applications
Post resources and
earn money
!
Related Resources
Repeater Control Sample
How to dynamically create controls using asp.net
ASP.NET Ajax Control (TextBoxWatermarkExtender,ValidatorCalloutExtender)
Sending E-Mail from Web Applications
Concurrency Control Using ADO.NET
dotNet Slackers
BizTalk Adaptors
Web Design
Contact Us
Privacy Policy
Terms Of Use