---
title: "How to use Session In Asp.net"  
description: "How to use Session In Asp.net"  
author: "Anonymous User"  
published: 2016-01-17  
updated: 2016-01-17  
canonical: https://www.mindstick.com/forum/33886/how-to-use-session-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net", "session"]  
reading_time: 1 minute  

---

# How to use Session In Asp.net

I want to use [Session](https://www.mindstick.com/articles/12042/session-in-c-sharp) In [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) How to use this Please Help me.

## Replies

### Reply by Anonymous User

Sessions we can be used to store data for the user specific like cookies.\
sessions will use cookies to store the data.\
Sessions we can used easily in ASP.NET with the Session object. We will re-use the cookie example,\
and use sessions instead. sessions will expire after a certain amount of minutes,as configured in the web.config file.

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sesion.aspx.cs" Inherits="Forumasp.Sesion" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title></title>     </head><body runat="server" id="Body">    <form id="form1" runat="server">        <div>            Change Body Color:            <asp:DropDownList runat="server" ID="color" AutoPostBack="True" OnSelectedIndexChanged="color_IndexChanged" Width="200">                <asp:ListItem Value="black" Selected="True">black</asp:ListItem>                <asp:ListItem Value="Blue">Blue</asp:ListItem>                <asp:ListItem Value="Red">Red</asp:ListItem>                <asp:ListItem Value="green">green</asp:ListItem>            </asp:DropDownList>        </div>    </form></body></html>CodeBehindusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace Forumasp{    public partial class Sesion : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            if (Session["BackgroundColor"] != null)            {                color.SelectedValue = Session["BackgroundColor"].ToString();                Body.Style["background-color"] = color.SelectedValue;            }        }        protected void color_IndexChanged(object sender, EventArgs e)        {            Body.Style["background-color"] = color.SelectedValue;            Session["BackgroundColor"] = color.SelectedValue;        }    }}
```

![How to use Session In Asp.net](https://www.mindstick.com/mindstickforums/8b842f6c-8f20-46d5-8b6e-bf2e4f017061/images/0ea1eb4b-d8ab-40b6-b73a-c444f22e140a.png)


---

Original Source: https://www.mindstick.com/forum/33886/how-to-use-session-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
