Showing posts with label Asp.net. Show all posts
Showing posts with label Asp.net. Show all posts

Explain what is Session in asp.net

Web application is maintaining user information over the course of a visit, or session, as the user moves from page to page in an application. Essentially, a session is the period of time that a unique user interacts with a Web application. HTTP is a stateless protocol.

Use of Cookies in .Net?

Cookie are one of several ways to store data about web site visitors during the time when web server and browser are not connected. Common use of cookies is to remember users between visits. Practically, cookie is a small text file sent by web server and saved by web browser on client machine.

Code to read a cookie in ASP.NET

string MyCookieValue;

if(Request.Cookies["MyCookieName"] != null)

{

MyCookieValue = Request.Cookies["MyCookieName"].Value;

}


Code to Delete cookie in ASP.NET?

First check if cookie exists

if (Request.Cookies["MyCookieName"] != null)

{

Response.Cookies["MyCookieName"].Expires = DateTime.Now.AddDays(-1);

}

HttpCookie class is located in System.Web namespace. You can use HttpCookie class to create and manipulate cookies.

Cookies size limits on Web browser?

Cookie size is limited to 4096 bytes. It is not much, so cookies are used to store small amounts of data, often just user id. - Also, number of cookies is limited to 20 per website. If you make new cookie when you already have 20 cookies, browser will delete oldest one.

Find does web browser accepts cookies or not?

Browser’s privacy settings. C# if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }