Click here to Skip to main content
16,011,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends

i have one application in that application i login using username and password then i access all pages in my aplication then after i logout.

this is main thing

i logout then after i type url like http://localhost:2424/sample/select.aspx
it ll be display.

i need to display login page in that time(any page i type above url i want to display login page).


and also after i logout i dont want to work back and forward button.

if i logout then after i click back or forward button i need to display login page.

Thanks&Regards
Venkat.S
Posted
Comments
Sergey Alexandrovich Kryukov 4-May-11 2:34am    
Do not re-post!
I'll remove your previous question (because this text is a bit longer).
--SA
Peter_in_2780 4-May-11 3:52am    
Didn't seem to discourage OP! See http://www.codeproject.com/Questions/191046/when-i-click-back-or-forward-button-wont-display-d.aspx
:mad: (not at you!)
Sandeep Mewara 4-May-11 4:32am    
I deleted it now!

For logout back button issue, look: Browser back button issue after logout[^]


For having a login button on URL navigation after logout:
At login, when user is authenticated:
C#
Session["IsLoggedIn"] = "Yes";
//OR
Session["LoggedInUserId"] = "User621";


At the time of logout, clear the session:
C#
Session.Clear();
//OR 
Session["IsLoggedIn"] = null;


If you want to check if user is logged in or not, just see if session value exists. If it's null then they are not authenticated and so direct them to Login URL.
 
Share this answer
 
On every page load just check the value of the Session, if this is null then simply just return to the login page.

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["UserID"] == null)
        Response.Redirect("loginPage.aspx");
}

but better approach is create another page e.g. BasePage and inherit it with "System.Web.UI.Page" and each .aspx.cs should inherit with this BasePage.

Now u can right this logic only once in the BasePage.

public class basePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            if (Session["UserID"] == null)
                Response.Redirect("loginPage.aspx");
            base.OnLoad(e);
        }
    }


public partial class _Default : basePage
 
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