c# - Read cookie to login automatic -
i store cookies when logging in, below:
list<user> listuser; //returns 1 user foreach(user u in listuser) { httpcookie cookienickname = new httpcookie("usernickname"); cookienickname.value = u.nickname.tostring(); cookienickname.expires = datetime.maxvalue; response.cookies.add(cookienickname); httpcookie cookiepassword = new httpcookie("userpassword"); cookiepassword.value = u.password; cookiepassword.expires = datetime.maxvalue; response.cookies.add(cookiepassword); }
when visits site again, want read data database associated usernickname-cookie , userpassword-cookie.
then want show firstname , lastname on label.
this tried:
list<user> cookieloggedinuser; if (request.cookies["usernickname"] != null && request.cookies["userpassword"] != null) { //returns 1 user cookieloggedinuser = database.signin(request.cookies["usernickname"].tostring(), request.cookies["userpassword"].tostring()); if (cookieloggedinuser.count > 0) { foreach (user u in cookieloggedinuser) { lblfirstname.text = u.firstname; lbllastname.text = u.lastname; } } }
but both of request.cookies return null.
why happening?
i wouldn't recommend approach took other experimeting purposes has big security risk.
to make curent solution work check creating cookies in same domain consume them.
if not case, browser not send cookies other domain.
Comments
Post a Comment