How To Show All session Key and Value In ASP.NET
Session is a powerful feature in web application to store information in server memory. by doing this, any data will be save temporary in server memory and can be access in the application.
This is a advantage and disadvantage of Session :
In this example, i will show how to create simple page to show all session key and value of session key. :
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
This is a advantage and disadvantage of Session :
Advantages:
- It helps maintain user state and data all over the application.
- It is easy to implement and we can store any kind of object.
- Stores client data separately.
- Session is secure and transparent from the user.
Disadvantages:
- 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.
In this example, i will show how to create simple page to show all session key and value of session key. :
Requirement
- aspx page and code behind
The Aspx Page
<h1>
Print All Session Key And Value</h1>
<br />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
The Code Behind
protected void Page_Load(object sender, EventArgs e)
{
String table = "";
table += "<table style=\"width:450px; border:1px solid #ccc;\"><tr>";
table += "<th>Session Key</th>";
table += "<th>Session Value</th>";
table += "</tr>";
for (int i = 0; i < Session.Keys.Count; i++)
{
table += "<tr>";
table += "<td>" + Session.Keys[i] + "</td>";
table += "<td>" + Session[i].ToString() + "</td>";
table += "</tr>";
}
table += "</table>";
Panel1.Controls.Add(new LiteralControl(table));
}
Sample Output
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)