Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
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>
  </div>
  <div>
  	<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>        
    </ul>
  </div>
 
 
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?
 
Thanks
Posted 17-Dec-12 0:27am
hasbina1.2K
Edited 17-Dec-12 0:52am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Use the below javascript code for prevent page last accessed
 
function deletehistory()
 
    {
 
    window.history.forward();
 
    }
 

<body onload="deletehistory()" >
  Permalink  
Comments
hasbina at 17-Dec-12 6:45am
   
@vishnu
i want a solution using session..
hasbina at 17-Dec-12 6:48am
   
That is, logout is a html link.can't use
Session.Abandon();
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
good
Please Sign up or sign in to vote.

Solution 2

I think on your "LogOut" button event, you need to clear session that is
 
Session.Clear();
Session.Abandon();
Response.Redirect("logout.html");
 
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)
{
Response.Redirect("login.aspx");
}
 
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.
Milind
  Permalink  
Comments
hasbina at 17-Dec-12 7:12am
   
@Milind_T
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
good
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)
Response.Redirect("Logout.aspx");
 
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>
  Permalink  
v2
Rate this: bad
good
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 
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore(); 
 
} 
 
 
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
 
<script>
window.onload= function  {
    history.go(-1);
}
</script></script>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 250
1 Sergey Alexandrovich Kryukov 184
2 Rob Philpott 100
3 jlopez788 74
4 CHill60 70
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,589
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web01 | 2.8.140721.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