Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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

ASP
<%@ 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
Updated 17-Dec-12 0:52am
v2

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

C#
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

C#
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
 
Share this answer
 
Comments
hasbina 17-Dec-12 7:12am    
@Milind_T
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.
'
MT_ 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?
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="/KB/answers/Logout.aspx";"></body>
 
Share this answer
 
v2
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

C#
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

JavaScript
<script>
window.onload= function  {
    history.go(-1);
}
</script></script>
 
Share this answer
 
Hi Use the below javascript code for prevent page last accessed

XML
function deletehistory()

    {

    window.history.forward();

    }


<body onload="deletehistory()" >
 
Share this answer
 
Comments
hasbina 17-Dec-12 6:45am    
@vishnu
i want a solution using session..
hasbina 17-Dec-12 6:48am    
That is, logout is a html link.can't use
Session.Abandon();
Session.Clear(); in click event.
MT_ 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900