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 () {
LoadCookies();
});
function LoadCookies() {
$.ajax({
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) {
console.log(response.d);
}
}
==================================================
=============== asp.net code======================
[System.Web.Services.WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod()]
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"]);
}
}
}
}