asp.net 判断 session

来源:百度知道 编辑:UC知道 时间:2024/07/03 13:04:17
protected void Page_Load(object sender, EventArgs e)
{

Response.Write(Session["type"]);
if (Session["type"] == "1")
{
Response.Write("You are administrator!");
}
}

输出来是 1 但是 为什么 if 里面的东西输出不来呢?

if (Session["type"] == "1")改成 if (Session["type"] != null && Session["type"].ToString() == "1")试试,如果还不行,肯定是没有等于字符串1的SESSION变量,建议跟踪下代码或查下数据库信息

Response.Write 会强制转换

Session["type"] 这样用的话,是一个 Object 对象
你要用 Session["type"].toString()