Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a simple HRMS web based application in C#. In this application there is no session implemented. There is master Page in my application and on the master page there is a menu button named LogOut , when i click to that button it redirect me to the index page of the application. and when i close the browser tab and again copy the same url it actually opens the page whatever page i want to open but not open the login page as expected.
Note: There is no logout page in the application, i am just redirecting it to the index.aspx page when logout clicked.
So please tell me how could i implement session to avoid this.

Here some code when user click to logiut:
HTML
<li><a href="Index.aspx">Logout</a></li>
Posted
Comments
harshavardhan12345678 1-Sep-14 2:49am    
click on postback property and select index.aspx k k

Hello ,
If you know any thing about session events try to implement it.
C#
Session.Clear();

Or
Session.RemoveAll();
Otherwise a simple approach would be to keep the userid in hidden field . When Clicked on Login keep that value in hidden field. When clicked on logout ,remove the value from hidden field.
Although try to Implement It The session.This Hidden field concept is not upto the mark.
 
Share this answer
 
On page load check whether session is null or not.

Example :

VB
If Session("XXXXX") Is Nothing Then Response.Redirect("Login.aspx")
 
Share this answer
 
You can use
C#
Session.Abandon();
 
Share this answer
 
v2
Session.Abandon();
Session.Remove("session_variable_name"); //it add key between double quotes
 
Share this answer
 
See this : how to clear a session after logout[^]

Set the session once user logs in and clear it at the time of logout. At the time user tries to access any page, check that session if it expired redirect to login page.

You can also Implement Simple Forms Authentication[^]

Regards..
 
Share this answer
 

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