我做了一个判断用户是否登录的类    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中的方法,如何在基类中就组织继承类中页面的执行,而直接进入登录页面呢?

解决方案 »

  1.   


    HttpContext.Current.ApplicationInstance.CompleteRequest();
    改成
    Response.End();
      

  2.   


    就是因为Response.End(); 会向系统事件中提交异常事件,比较不爽,才将他换成
    HttpContext.Current.ApplicationInstance.CompleteRequest(); 的
      

  3.   

    在你自定义的基类的
    [code=Cstring msg = "<script>alert('没有登录或登录超时,请重新登陆');window.parent.location.href='/Web/Admin/AdminLog.aspx';</script>";
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);#][/code]
    下面加上return;试试
      

  4.   

    好了,解决了这个原因是我调用的这个
    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), null, msg);
    必须需要页面加载后才能运行
    所以我直接用Response.Write(msg);来打印了脚本
    这样后面就可以结束了,貌似这个 ApplicationInstance.CompleteRequest(); 没有起作用
    所以我就直接用                try
                    {
                        Response.End();
                    }
                    catch (System.Threading.ThreadAbortException lException)
                    {
                        // do nothing
                    }来解决出现异常的问题了
    好了,感谢继位的回答,结贴!
      

  5.   

        protected override void OnLoad(EventArgs e)
        {
            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);
                //.........其它代码
            }
        }
      

  6.   

    没刷新,没看到7楼。不需要try....catch,因为Response.End()本来就是靠内部抛出异常来退出页面的。此外你的Base.OnLoad显然位置不对。