Click here to Skip to main content
11,922,789 members (59,289 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET

I create a consistent layout for the pages using web usercontrol as below,

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="M2iSTS2.UserControl.Header" %>
<link href="/Styles/styles.css" rel="stylesheet" type="text/css" />
 <div id="header" class="header">
  	<h1 class="h1">TrackU: Student and Vehicle Tracking System</h1>
    <p class="p"><a class="a" href="/Account/login.aspx">Logout</a></p>
  	<ul class="ul">
    	<li class="li"><a class="lia" href="/Admin/Fleet.aspx">Fleet</a></li>
        <li class="li"><a class="lia" href="/Admin/StudentInfo.aspx">Student Info</a></li>        
        <li class="li"><a class="lia" href="/Admin/RouteSettings.aspx">Route Settings</a></li>        
        <li class="li"><a class="lia" href="/Admin/Reports.aspx">Reports</a></li>        

when i click logout link in each page, it redirect to login.aspx.Then,
when i click back button in browser it go back to previous page, not to login page.

when use the logout as server control inside a form tag,
cant add another form inside the server-form.

how to avoid this?

Posted 17-Dec-12 1:27am
Edited 17-Dec-12 1:52am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I think on your "LogOut" button event, you need to clear session that is


Once you click this button you session is gone.
Now add code on the pageload of the common control to check if the session is active or gone as below

if(Session["username"] == null)

This is the most general way logout is handled. And it should serve your purpose unless I have misunderstood your requirement.

Hoep that helps. If it does, mark as answer/upvote.
hasbina 17-Dec-12 7:12am
sir, "LogOut" is html control, it is the problem
hasbina 17-Dec-12 7:15am
when i change it to linkbutton inside a form tag,
it giving error as 'A page can have only one server-side Form tag.
Milind_T 17-Dec-12 7:34am
@hasbina: Right, But make your logout control clickable. OnClientClick also you can clear session and then redirect the user to the page rather than directly giving href !! Right?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

1) On all the pages that are only available to authenticated users, include:
< %@ OutputCache Duration = "1" NoStore="true" Location="None" % >

2) On PageLoad event of every secured page, check:
if(Session["loggedInUser"] == null)

3) On click of log out button, clear session with Session.Abandon();Session.Clear(); then redirect the user to PreLogout.aspx page.

4) Include this javascript in the body tag of PreLogout.aspx page:
<body önload="top.location.href = 'Logout.aspx';"></body>
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

You need to disable page caching in the browser. And this can be done via server side event or if you want to do it on client side, you need to use the trick the history of the browser. Here are both the ways

Server side

public static void DisablePageCaching() 
//Used for disabling page caching 

Client side on your logout page.. But remember to test in all browsers , since all the browsers may not support this ... The server side option is always the best

window.onload= function  {
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi Use the below javascript code for prevent page last accessed

function deletehistory()

<body onload="deletehistory()" >
hasbina 17-Dec-12 6:45am
i want a solution using session..
hasbina 17-Dec-12 6:48am
That is, logout is a html link.can't use
Session.Clear(); in click event.
Milind_T 17-Dec-12 6:56am
I dont think OP is asking how to remove history. This is more like session handling question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100