咨询电话:186 7916 6165 咨询电话:186 7916 6165 (微信同号)    在线QQ:181796286
NEWS BLOG ·
学无止境
关注开优网络 关注前沿
ASP.NET 获取IP地址
ASP.NET Linq to XML

session验证放在继承类中

发表日期:2015-09-16    文章编辑:南昌开优网络    浏览次数:3838    标签:ASP.NET应用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NCNEWS.Web
{
    public class ValidatorPage : System.Web.UI.Page
    {
        //pageunload事件,并不是指浏览器关闭,而是指页面关闭,所以刷新的时候,依然会执行以下事件 
        protected void Page_Unload(object sender, EventArgs e)
        {
        }

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
            if (Session["user"] == null)
            {//这里写 跳转到登陆页面:例如: 
              //  Response.Redirect(string.Format("/adminlogin.aspx?page={0}", Server.UrlEncode(Request.Url.ToString())));
                Response.Write("<script>window.parent.location.href='"+Xiaobin.Utility.Tool.GetApplicationPath()+"admin/login.aspx'</script>");
                Response.End();
            }
        }
    }
}