ASP.Net Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 791 Page Views: 

Write the code to write cookie from a client's computer.



Posted By: Avi Date: 3 October 2010 12:43:19 PM
 Answer:

The following code write a cookie to the user client. The cookie is "User" stores Username,Password and LastVisit.Assuming that the user interface is already designed with controls to enter "Username" and "Password" and there is a button to write the cookie. The button is named "Write Cookie".Code for the write cookie is as follows:- protected void WriteCookieButton_Click(object sender, EventArgs e) { // Create an instance of HttpCookie class HttpCookie UserCookie = new HttpCookie("User"); // Populate Username, password and LastVisit fields UserCookie["username"] = UsernameTextBox.Text; UserCookie["Password"] = PasswordTextBox.Text; UserCookie["LastVisit"] = DateTime.Now.ToString(); // Set the cookie expiration date UserCookie.Expires = DateTime.Now.AddDays(3); // Write the cookie to the client computer Response.Cookies.Add(UserCookie); }


Posted By: avibtech


Date: 3 October 2010 12:43:19 PM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image 1x6WDh
Related Questions
ASP.Net : Can you tell me the two properties common in every validation controls?

Can you tell me the two properties common in every validation controls?

ControlToValidate property and Text property
Category: ASP.Net Date: 10/28/2009 4:44:15 AM
ASP.Net : What is the difference between trace and debug in ASP.NET?

What is the difference between trace and debug in ASP.NET?

Debug and trace enables you to monitor the application for errors and exception without VS.NET IDE. ....
Category: ASP.Net Date: 10/27/2009 4:56:34 AM
ASP.Net : How can we force all the validation controls to run?

How can we force all the validation controls to run?

Use following server-side C# code: Page.Validate();
Category: ASP.Net Date: 10/27/2009 4:49:04 AM
ASP.Net : What is impersonation in ASP.Net?

What is impersonation in ASP.Net?

Impersonation is when ASP.Net executes code in the context of an authenticated and authorized client....
Category: ASP.Net Date: 10/25/2009 6:08:34 AM
ASP.Net : Where is the ViewState information stored in ASP.Net page?

Where is the ViewState information stored in ASP.Net page?

ASP.Net uses HTML Hidden Fields to store ViewState information.
Category: ASP.Net Date: 10/15/2009 5:30:13 AM