IntroductionWe use Session in ASP.NET application to maintain the state of the user. These Sessions too use Cookies in the background to associate Sessions with the correct user. But if a user has turned off his browser's cookies then our application will not work on these browsers. For this situation we use Cookie-less Sessions. In Cookie-less Sessions, the values that are required to associate users with their sessions are appended to the browser's URL.SessionAs we know HTTP is a stateless protocol and every request to a web page is treated as a new request. Session is a way of maintaining the state of a page. A session stores user specific data that persists across multiple page requests. We can store any type of object in a session.ExampleSession.Add("Name", txtName.Text); Session["Name"] = " txtName.Text;Here, both statements can be used to store a value of the "txtName" TextBox in Session.Similarly, we can also add any other object in the session, like a DataSet.SqlConnection con = new SqlConnection(ConString);SqlCommand cmd = new SqlCommand("SELECT * FROM Employee", con);SqlDataAdapter sda = new SqlDataAdapter(cmd);DataSet ds = new DataSet();sda.Fill(ds);To retrieve the session value, we can use the following code:if (Session["Name"] != null){ txtName.Text = Session["Name"].ToString(); }First, we check if a session with name "Name" exists. Then we put the session vaule in the TextBox.How to Cookie-less SessionBy default a session uses a cookie in the background. To enable a cookie-less session, we need to change some configuration in the Web.Config file. Follow these steps:
<sessionState cookieless="AutoDetect" regenerateExpiredSessionId="true"/>
The possible values for "cookieless" attribute are:
"regenerateExpiredSessionId" is used to ensure that if a cookieless url is expired a new new url is created with a new session. And if the same cookieless url is being used by multiple users an the same time, they all get a new regenerated session url.We have configured our "Web.config" file to enable cookieless session. Now, its time to test it. Open Mozilla Firefox and Click on (Tools -> Options -> Pricacy)Now on History group box select (Firefox will : Use custom settings for history)Now uncheck (Accept cookeies from sites)You will get an URL something like this:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: