Remove all keys and values from the session-state collection
SessionRemoveAll.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e) {
Session["CustomerID"] = "12";
Session["CustomerName"] = "Ben Forta";
Label1.Text = "Session read...<br />";
Label1.Text += "Customer ID : " + Session["CustomerID"];
Label1.Text += "<br />Customer Name : " + Session["CustomerName"];
Label1.Text += "<br> Now remove all items from session.";
Session.RemoveAll();
Label1.Text += "<br /><br />Customer ID : " + Session["CustomerID"];
Label1.Text += "<br />Customer Name : " + Session["CustomerName"];
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net session RemoveAll example: how to remove all keys and values from the session-state collection</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">asp.net session example: Session RemoveAll</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="RosyBrown"
>
</asp:Label>
</div>
</form>
</body>
</html>