Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a load cookie function which is developed for "Remember me" functionality to my site. It is working fine but one issue is ,when the site is loading for first time , say end user has set the remember me section then logon to the site,after using it he/she close the browser, after he/she open the browser and then try to load the site ,the cookie is loading but as the loading time the cookie sets the session values so that the user gets to see log in button ,next time the end user clicks any area to interact with the site after 2nd page load the user gets to see he/she is logged on, this is the issue , Is there any way to process the cookie before the page loads so that it sets the session before page load and user can see he/she is logged on in the first attempts

What I have tried:

================= javascript code ======================
$(document).ready(function () {
function LoadCookies() {
        type: "POST",
        url: "index.aspx/LoadCookie",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        failure: function (response) { alert("write log failure " + response.d); }
    function onSuccess(response) {

=============== code======================
[System.Web.Services.WebMethod(EnableSession = true)]
        public static void LoadCookie()
            BidderBL objBidderBL = new BidderBL();
            if (HttpContext.Current.Request.Cookies["LoginCookie"] != null)
                if (HttpContext.Current.Request.Cookies["LoginCookie"].Values["UserName"] != null)
                    string Email = HttpContext.Current.Request.Cookies["LoginCookie"].Values["UserName"].Trim().ToString();
                    string Password = HttpContext.Current.Request.Cookies["LoginCookie"].Values["Password"].Trim().ToString();
                    string UserType = "1";
                    DataTable dtLogin = objBidderBL.GetLoginUser(Email, Password, UserType);
                    if (dtLogin != null && dtLogin.Rows.Count > 0)
                        HttpContext.Current.Session["UserType"] = "Bidder";
                        HttpContext.Current.Session["UserName"] = Convert.ToString(dtLogin.Rows[0]["PreferredName"]);
                        HttpContext.Current.Session["UserId"] = Convert.ToString(dtLogin.Rows[0]["BidderId"]);
Updated 25-Sep-16 22:12pm

1 solution

The easiest way to handle this is to simply redirect the person after they login. So redirect them either to the same page they were on, or to a "my account" type page, such that the site works as normal without you having to modify much.

Also I hope you're not storing the password in the cookie in plain text?
Share this answer
Arnab Kundu 27-Sep-16 1:25am    
Thank you for your reply . Yes I'm storing the password in the cookie in plain text,I just wanna clarify one thing that,in my flow I can't redirect to any page .say,If a user sets the remember me option then next time when he logs in to the site he/she probably need to see he/she is already logged in to the site ,as my cookie will expire after 15 days,my problem is as I'm getting the cookie value in the 1st load and setting the session value at that time so that at the 1st time user can't able to see he/she is logged in actually .As the session sets in the first load ,when he/she will clicks anywhere to reload any page again he/she will able to see he/she is logged on ,I need to fix such a way,before the page loads I've to set the session values

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