Session
Introduction of session and types of session.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted May 8, 2012, 6:00 PM EDT
Sessions can be used to store even complex data for the user just like cookies. Actually, sessions will use cookies to store the data, unless you explicitly tell it not to. Sessions can be used easily in ASP.NET with the Session object. We will re-use the cookie example, and use sessions instead. Keep in mind though, that sessions will expire after a certain amount of minutes, as configured in the web.config file. Markup code:
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> html xmlns="http://www.w3.org/1999/xhtml" > head runat="server"> title>Sessionstitle> head> body runat="server" id="BodyTag"> form id="form1" runat="server"> asp:DropDownList runat="server" id="ColorSelector" autopostback="true" onselectedindexchanged="ColorSelector_IndexChanged"> asp:ListItem value="White" selected="True">Select color...asp:ListItem> asp:ListItem value="Red">Redasp:ListItem> asp:ListItem value="Green">Greenasp:ListItem> asp:ListItem value="Blue">Blueasp:ListItem> asp:DropDownList> form> body> html>using System; using System.Data; using System.Web; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(Session["BackgroundColor"] != null) { ColorSelector.SelectedValue = Session["BackgroundColor"].ToString(); BodyTag.Style["background-color"] = ColorSelector.SelectedValue; } } protected void ColorSelector_IndexChanged(object sender, EventArgs e) { BodyTag.Style["background-color"] = ColorSelector.SelectedValue; Session["BackgroundColor"] = ColorSelector.SelectedValue; } }1)InProc
2)OutProc
An inproc is one, which runs in the same process area as that of the client giving the advantage of speed but the disadvantage of stability because if it crashes it takes the client application also with it. Outproc is one, which works outside the client's memory thus giving stability to the client, but we have to compromise a bit on speed.
Also Please refer Our recommended articles
Thanks
MuthuMari MRank #5,738 · 288 reputationPosted May 8, 2012, 10:49 PM EDT
A variable is stored temporary in the computer memory, but sometimes we need to hold data across different pages. Here is when Session Variables come very helpful. They can retain their values as long as the user:
(unless specified otherwise)
To create a session variables:
Session("VariableNameHere") = "VariableValueHere"
To set a different session time out in minutes:
Session.TimeOut = 40
To remove the session variable:
Session.Contents.Remove("VariableNameHere")
pls refer this url :http://www.c-sharpcorner.com/UploadFile/ganesh.nataraj/ASPdotNETSessionState09212005235624PM/ASPdotNETSessionState.aspx
thanks