Jedi Ablaza Jedi Ablaza - 3 months ago 18
ASP.NET (C#) Question

hwo to end session in asp.net using html

I want to know how can I end or clear the session when the user clicks "Log Out" from the navbar? I am using

<a></a>
tag and I can't seem to think how to end the session.

Below is my code thats how I made my tag and I don't know where can I put the session end command. How will i do it? Thanks!

<div class ="navbar navbar-inverse navbar-fixed-top" style="background-color:cornflowerblue">
<div class="container-fluid">
<a class="navbar-brand" href="Default.aspx" runat="server" style="color:white; font-family:FrizQuaBol">&emsp;&emsp;&emsp;&emsp;&emsp;Yusen Logistics Philippines, Inc.</a>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a id="forAdmin" runat="server" href="#" style="color:white;font-family:Calibri">Admin controls</a></li>
<li><a id="forAdmin2" runat="server" href="#" style="color:white;font-family:Calibri">Maintenance</a></li>
<%--<li><a href="Requests.aspx" style="color:white">Requests</a></li>--%>
<li><a href="MyRequests.aspx" style="font-family:Calibri; color:white">My Requests</a></li>
<li class="dropdown">
<a id="admins" class="dropdown-toggle" data-toggle="dropdown" runat="server" style="color:white; font-family:Calibri; cursor:pointer">Requests <%--(<asp:Label ID="lblcount" runat="server" Text="#"></asp:Label>)--%></a>
<ul class ="dropdown-menu">
<li><a id="app1" runat="server" href="/MOSEF/PendingRequests.aspx" style="font-family:Calibri">Pending Requests <%--(<asp:Label ID="lblPending" runat="server" Text="#"></asp:Label>)--%></a></li>
<li><a id="app2" runat="server" href="/MOSEF/ApprovedRequests.aspx" style="font-family:Calibri">Approved Requests <%--(<asp:Label ID="lblApprove" runat="server" Text="#"></asp:Label>)--%></a></li>
<li><a id="app3" runat="server" href="/MOSEF/NotedRequests.aspx" style="font-family:Calibri">Noted Requests <%--(<asp:Label ID="lblApprove" runat="server" Text="#"></asp:Label>)--%></a></li>
<li><a id="app4" runat="server" href="/MOSEF/PendingHistory.aspx" style="font-family:Calibri">History <%--(<asp:Label ID="lblApprove" runat="server" Text="#"></asp:Label>)--%></a></li>
<%--<li><a href="#" style="font-family:Calibri">Accepted Requests (<asp:Label ID="lblAccept" runat="server" Text="#"></asp:Label>)</a></li>--%>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><asp:Label ID="lblName" runat="server" CssClass="control-label" Text="#" Visible="false"></asp:Label></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">

<a id ="lblnames" class="dropdown-toggle" data-toggle="dropdown" runat="server" style="color:white; cursor:pointer">#</a>
<ul class ="dropdown-menu">
<li><a href="Account/Manage.aspx" style="font-family:Calibri">Manage Account</a></li>
<li><a id="endsession" href="../Account/LogInNoMaster.aspx" style="font-family:Calibri">Log Out</a></li>
</ul>
</li>
<%--<li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !</a></li>
<li>
<asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
</li>--%>
</ul>
</div>

Answer

Add A new aspx page and in page load function add the following code and specify redirect

Session.Abandon()
Response.Redirect("default.aspx")

and in your html add some code like this

 <li><a id="app5" runat="server" href="/MOSEF/your_new_page.aspx" style="font-family:Calibri">Logout</a></li>
Comments