学无止境详情

session验证放在继承类中

发表:2015-09-16    编辑:南昌开优网络    浏览:3885    
标签: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();
            }
        }
    }
}
分享
  1. 上一篇:ASP.NET 获取IP地址
  2. 下一篇:ASP.NET Linq to XML