A method that deletes a persistent cookie

private void DeleteCookie()
HttpCookie nameCookie = new HttpCookie("UserName");
nameCookie.Expires = DateTime.Now.AddSeconds(-1);

A hyperlink with a URL that includes a query string
<asp:HyperLink ID="HyperLinkl" runat="server" NavigateUrl="~/w3asp.aspx?cat=fx&prod=fogOl">Pog machine

An anchor element with a URL that includes a query string
<a href="w3asp.aspx?cat=fx&prod=fog01">Fog machine</a>
Statements that retrieve the values of the query string attributes
string categorylD = Request.QueryString["cat"];
string productID = Request.QueryString["prod"];

Code that uses a URL with a query string in a Redirect method
Response.Redirect("w3asp.aspx?cat=" + categorylD);

The web.config file has a connectionStrings element that contains an add element for each connection string. In the example, the connection string is named w3aspConnectionString,and the connection string refers to a database named Halloween on the server named localhost\sqlexpress.The ConnectionStrings section of the web.config file-


<add name="w3aspConnectionString" connectionString="DataSource=localhost\sqlexpress; Initial Catalog=w3asp;Integrated Security=True"



There are two types of session events available in ASP.NET:

  • Session_Start
  • Session_End
You can handle both these events in the global.asax file of your web application. When a new session initiates, the session_start event is raised, and the Session_End event raised when a session is abandoned or expires.

We know that Http is stateless, means when we open a webpage and fill some information and then move to next page then the data which we have entered will lost.It happed do to Http protocol stateless nature. So here session come into existence, Session provide us the way of storing data in server memory. So you can store your page data into server memory and retrieve it back during page postbacks.

Stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of requests and responses.

State management is the process by which you maintain state and page information over multiple requests for the same or different pages.


  • Session provide us the way of maintain user state/data.
  • It is very easy to implement.
  • One big advantage of session is that we can store any kind of object in it. eg, datatable, dataset etc
  • By using session we do not need to worry about data collapsed, because it store every client data separately.
  • Session is secure and transparent from the user.
  • Performance overhead in case of large volumes of data/user, because session data is stored in server memory.
  • Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.

Asp.Net use 120 bit identifier to track each session. This is secure enough and can not be reverse engineered. When client communicate with server, only session id is transmitted, between them. When client request for data, ASP.NET looks on to session ID and retrieves corresponding data.

By default, the unique identifier for a session is stored in a non-expiring session cookie in the browser. You can specify that session identifiers not be stored in a cookie by setting the cookieless attribute to true in the sessionState configuration element. We can also configure our application to store it in the url by specifying a "cookieless" session.The ASP Session cookie has this format:-


PreviousDisplaying 5 of 7Next
1 2 3 4 5 6 7
Need Help? Contact Us.

Log in


Forgot password?


New User