相关文章推荐
行走的豆芽  ·  python ...·  2 年前    · 
想出家的墨镜  ·  Triaging Patients ...·  2 年前    · 
不羁的山羊  ·  SpringCloud gateway ...·  2 年前    · 
){outline:none;box-shadow:none;}select::-ms-expand{;}:root,:host{--chakra-vh:100vh;}@supports (height: -webkit-fill-available){:root,:host{--chakra-vh:-webkit-fill-available;}}@supports (height: -moz-fill-available){:root,:host{--chakra-vh:-moz-fill-available;}}@supports (height: 100dvh){:root,:host{--chakra-vh:100dvh;}}
Link to home
Create Account Log in
Avatar of weerdboil
weerdboil

asked on

Unable to cast object of type 'System.Web.HttpCookie' to type 'System.IConvertible'.
I get the following error:
Unable to cast object of type 'System.Web.HttpCookie' to type 'System.IConvertible'.
from this code:
public static bool validateMember()
if (HttpContext.Current.Sessi on["member _id"] != null)
object oMemberID = HttpContext.Current.Sessio n["member_ id"];
if (Convert.ToInt16(oMemberID ) > 0)
return true;
return false;
return false;
bit weird because this only happens on live server (IIS) compared to local (Vis Studio)
Any ideas?
Thanks,
Avatar of Havagan
The error "Unable to cast object of type 'System.Web.HttpCookie' to type 'System.IConvertible'." points at the object stored in "HttpContext.Current.Sessi on["member _id"]" being a cookie and not an integer. To be sure check the type of the object in session.
What does the code which sets HttpContext.Current.Sessio n["member_ id"] look like?
Avatar of weerdboil
the code is basically this:
intUserID = Convert.ToInt16(dr["user_i d"]);
Session["member_id"] = intUserID;
I was setting this also if the cookie had a value on a return visit
Session["member_id"] = Request.Cookies["ekbfitnes s_member_i d"];
so this must be the problem.
have changed it to this:
int intMemberID = Convert.ToInt16(Request.Co okies["ekb fitness_me mber_id"]) ;
Session["member_id"] = intMemberID;
so hopefully should work now?
Thanks,
Avatar of weerdboil
changed it to Session["member_id"] = Request.Cookies["ekbfitnes s_member_i d"];
Seems to be working now I hope....
Avatar of weerdboil
hmmm.
nope. should test properly before posting.