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

这个类应该继承自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();
}

}
}
}
原文地址:https://www.cnblogs.com/leotian/p/1336484.html