我做了一个判断用户是否登录的类 public class IsAdminLogin : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnLoad(e);
if (HttpContext.Current.Session["Adminmage"] == null || HttpContext.Current.Session["Admin_ID"] == null || HttpContext.Current.Session["AdminType"] == null)
{
string msg = "<script>alert('没有登录或登录超时,请重新登陆');window.parent.location.href='/Web/Admin/AdminLog.aspx';</script>";
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
else
{
AdminID = int.Parse(System.Web.HttpContext.Current.Session["Admin_ID"].ToString());
AdminName = System.Web.HttpContext.Current.Session["Adminmage"].ToString();
AdminType = int.Parse(System.Web.HttpContext.Current.Session["AdminType"].ToString());
}
} public IsAdminLogin()
{ } int _adminID;
string _adminName;
int _adminType; /// <summary>
/// 后台登录用户的ID
/// </summary>
public int AdminID
{
get { return _adminID; }
set { _adminID = value; }
} /// <summary>
/// 后台登录用户的用户名
/// </summary>
public string AdminName
{
get { return _adminName; }
set { _adminName = value; }
} /// <summary>
/// 管理员类性 0超级管理员,1市场部经理,2财务,3程序员,4销售
/// </summary>
public int AdminType
{
get { return _adminType; }
set { _adminType = value; }
}
}
然后在页面中继承了这个类public partial class Admin_MediaAdMgr : CycbizB2C.BLL.PublicManage.IsAdminLogin
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(1111); //如何控制不让这行执行呢?
}
}
虽然集成后,确实可以判断用户是否登录等等,但是他还是要执行一次Page_Load中的方法,如何在基类中就组织继承类中页面的执行,而直接进入登录页面呢?
{
protected override void OnInit(EventArgs e)
{
base.OnLoad(e);
if (HttpContext.Current.Session["Adminmage"] == null || HttpContext.Current.Session["Admin_ID"] == null || HttpContext.Current.Session["AdminType"] == null)
{
string msg = "<script>alert('没有登录或登录超时,请重新登陆');window.parent.location.href='/Web/Admin/AdminLog.aspx';</script>";
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
else
{
AdminID = int.Parse(System.Web.HttpContext.Current.Session["Admin_ID"].ToString());
AdminName = System.Web.HttpContext.Current.Session["Adminmage"].ToString();
AdminType = int.Parse(System.Web.HttpContext.Current.Session["AdminType"].ToString());
}
} public IsAdminLogin()
{ } int _adminID;
string _adminName;
int _adminType; /// <summary>
/// 后台登录用户的ID
/// </summary>
public int AdminID
{
get { return _adminID; }
set { _adminID = value; }
} /// <summary>
/// 后台登录用户的用户名
/// </summary>
public string AdminName
{
get { return _adminName; }
set { _adminName = value; }
} /// <summary>
/// 管理员类性 0超级管理员,1市场部经理,2财务,3程序员,4销售
/// </summary>
public int AdminType
{
get { return _adminType; }
set { _adminType = value; }
}
}
然后在页面中继承了这个类public partial class Admin_MediaAdMgr : CycbizB2C.BLL.PublicManage.IsAdminLogin
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(1111); //如何控制不让这行执行呢?
}
}
虽然集成后,确实可以判断用户是否登录等等,但是他还是要执行一次Page_Load中的方法,如何在基类中就组织继承类中页面的执行,而直接进入登录页面呢?
解决方案 »
- ASP.NET弹出带有“是”和“否”的对话框问题(在线等!急)
- 您把哪些东东看成了对象?
- 关闭数据库
- 帮看下这个asp.net开发的小问题
- ASP.net中如何把整个Project编译成一个程序集(dll)
- 想用ASP.NET2.0的角色管理,对每个页面进行权限分配.大虾给个思想,谢谢.
- ============急=====再出70分请大家帮忙看一下下面100分求一个问题的贴子===================================
- 如何让Socket侦听80端口。
- AJAX刷新页面怎么保存结果?
- 怎样用.NET制作一个登陆的客户端啊???
- FCKeditor 问题
- 帮个忙解释下这个JS代码
HttpContext.Current.ApplicationInstance.CompleteRequest();
改成
Response.End();
就是因为Response.End(); 会向系统事件中提交异常事件,比较不爽,才将他换成
HttpContext.Current.ApplicationInstance.CompleteRequest(); 的
[code=Cstring msg = "<script>alert('没有登录或登录超时,请重新登陆');window.parent.location.href='/Web/Admin/AdminLog.aspx';</script>";
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);#][/code]
下面加上return;试试
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);
必须需要页面加载后才能运行
所以我直接用Response.Write(msg);来打印了脚本
这样后面就可以结束了,貌似这个 ApplicationInstance.CompleteRequest(); 没有起作用
所以我就直接用 try
{
Response.End();
}
catch (System.Threading.ThreadAbortException lException)
{
// do nothing
}来解决出现异常的问题了
好了,感谢继位的回答,结贴!
{
if (HttpContext.Current.Session["Adminmage"] == null || HttpContext.Current.Session["Admin_ID"] == null || HttpContext.Current.Session["AdminType"] == null)
{
this.Response.Write("<script>alert('没有登录或登录超时');window.parent.location.href='/Web/Admin/AdminLog.aspx';</script>");
this.Response.End();
}
else
{
base.OnLoad(e);
//.........其它代码
}
}