您的位置:首页 > 编程语言 > C#

C#类中使用Session的正确方法

2014-03-22 23:35 190 查看
这个类应该继承自System.Web.UI.Page

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace AppName.App_Data
{
public class CheckLogin :System.Web.UI.Page
{
public CheckLogin()
{
object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];
if (IsLogined != null)
{
if (IsLogined.ToString()!="1")
{
HttpContext.Current.Response.Write("Error!");
HttpContext.Current.Response.End();
}
else
{
HttpContext.Current.Response.Write("OK");
}
}
else {
HttpContext.Current.Response.Write("Error!");
HttpContext.Current.Response.End();
}

}
}
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  VS.NET