basepage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace work012
{
public class BasePage :System.Web.UI.Page
{
public BasePage()
{
this.Load += new EventHandler(BasePage_Load);
}
protected void BasePage_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
//Response.Redirect("Login.aspx");
Response.Write("无权限<br>");
}
}
}
}
login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="work012.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="点击触发回发加载" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace work012
{
public partial class Login : BasePage
{
private string date;
protected void Page_Load(object sender, EventArgs e)
{
if (date == null)
{
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
Response.Write("Time Now is " + date + "<br>");
if (!IsPostBack)
{
Response.Write("第一次加载<br>");
}
else
{
Response.Write("回发加载<br>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}