我要写一个judge.aspx,来判断Session,当它为空时,我在判断Cookie是否存在,我自己写了,可是当我在别人的机器上登录时,显示错误,望高手指教. //当Session不对的时候,
if(Session["flag"] ==null || Convert.ToBoolean(Session["flag"]) != true)
{
//判断Cookie是否为空
HttpCookie myCookie = Request.Cookies["phone"];
string phoneNumber = Convert.ToString(myCookie.Value);
if(phoneNumber==null || phoneNumber == "")
{
Page.RegisterStartupScript("script","<script>alert('您还没有登录,请登录!');window.location.href='/MessageBook/admin_login.aspx';</script>");
}
else
{
Session["flag"] = true; }
}
if(Session["flag"] ==null || Convert.ToBoolean(Session["flag"]) != true)
{
//判断Cookie是否为空
HttpCookie myCookie = Request.Cookies["phone"];
string phoneNumber = Convert.ToString(myCookie.Value);
if(phoneNumber==null || phoneNumber == "")
{
Page.RegisterStartupScript("script","<script>alert('您还没有登录,请登录!');window.location.href='/MessageBook/admin_login.aspx';</script>");
}
else
{
Session["flag"] = true; }
}
{
if(!Convert.ToBoolean(Session["flag"]) )
{
//判断Cookie是否为空
HttpCookie myCookie = Request.Cookies["phone"];
string phoneNumber = Convert.ToString(myCookie.Value);
if(phoneNumber==null ¦ ¦ phoneNumber == "")
{
Page.RegisterStartupScript("script"," <script> alert('您还没有登录,请登录!');window.location.href='/MessageBook/admin_login.aspx'; </script> ");
}
else
{
Session["flag"] = true; }
}
}
未将对象引用设置到对象的实例。
行 28: string phoneNumber = Convert.ToString(myCookie.Value);
其实这一行是没有错误,不知为什么,请高手指点一下啊.