Click here to Skip to main content
Rate this: bad
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 0:27am
Edited 17-Dec-12 0:52am
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 at 17-Dec-12 6:45am
i want a solution using session..
hasbina at 17-Dec-12 6:48am
That is, logout is a html link.can't use
Session.Clear(); in click event.
Milind_T at 17-Dec-12 6:56am
I dont think OP is asking how to remove history. This is more like session handling question.
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 at 17-Dec-12 7:12am
sir, "LogOut" is html control, it is the problem
hasbina at 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 at 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  {

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 475
1 OriginalGriff 280
2 BillWoodruff 230
3 CPallini 220
4 ChauhanAjay 149
0 OriginalGriff 6,609
1 Sergey Alexandrovich Kryukov 6,240
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522

Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
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