set cookie to expire at end of session? asp.net

前端 未结 4 1507
无人及你
无人及你 2020-12-01 14:01

I\'m surprised I couldn\'t find any answers.

How do I set my sessionid in my cookie to expire at the end of session? (when the browser closes or the user has been in

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 14:17

    Do NOT use Login control, it makes it harder.

    protected void btnLogin_Click(object sender, EventArgs e) 
    {
        // Check user and password in database
        bool isValidUser = ValidateUser(txtUsername.Text, txtPassword.Text);
    
        // Set cookie to be not persistent - this means if the user closes the browser, 
        //autentification cookie will be deleted and the user is not longer logged 
        bool isPersistentCookie = false;
    
        // Login user with the new username
        FormsAuthentication.SetAuthCookie(txtUsername.Text, isPersistentCookie);
    }
    

提交回复
热议问题