Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guys, i have a asp.net web site app, use of membership for the authentication, but i have a problem that:
1. when i login,
2.and close my web site,
3.type one page URL (which needed to log in and can be visited)
but i can directly reach this page without login this time(after i closed the web site app).

so how can i solve the problem plz, here is my master page's code snippet:

C#
protected void Page_Load(object sender, EventArgs e)
{
    //close browser then logout
    //what should be here??may be

    //log out then back button not work
    Response.Cache.SetNoStore();
}

//works fine here
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
    Session.RemoveAll();
    Session.Abandon();
    Session.Clear();
    FormsAuthentication.SignOut();
    FormsAuthentication.RedirectToLoginPage();
}


tried several methods but failed..so, i just want to log in after i close my website browser without click the logout button,thanks in advance!
Posted
Updated 16-Jan-14 2:01am
v3
Comments
♥…ЯҠ…♥ 16-Jan-14 8:09am    
are you using javascript in your application?

You need to rely on cookie for achieving this.
 
Share this answer
 
Hi,

I think you need to clear the session at browser exit.
You can refer this[^] link and this [^].

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
Use Cookies to save User name and password to browser

VB
Protected Sub Login_Click(ByVal sender As Object, ByVal e As EventArgs)
    If chkRememberMe.Checked Then
        Response.Cookies("UserName").Expires = DateTime.Now.AddDays(30)
        Response.Cookies("Password").Expires = DateTime.Now.AddDays(30)
    Else
        Response.Cookies("UserName").Expires = DateTime.Now.AddDays(-1)
        Response.Cookies("Password").Expires = DateTime.Now.AddDays(-1)
    End If
    Response.Cookies("UserName").Value = txtUserName.Text.Trim
    Response.Cookies("Password").Value = txtPassword.Text.Trim
End Sub



Call on Page Load
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null)
        {
            txtUserName.Text = Request.Cookies["UserName"].Value;
            txtPassword.Attributes["value"] = Request.Cookies["Password"].Value;
        }
    }
}
 
Share this answer
 
found that, just in login page, use

C#
FormsAuthentication.SetAuthCookie(Login, false); // previously, i set true...now worked!
Response.Redirect("~/WelcomPage.aspx",false);
 
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