您的位置:首页 > 编程语言 > ASP

asp.net 继承自Page实现统一页面验证与错误处理

2012-10-10 16:45 751 查看
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
///first write
///up by ahuinan 2009-4-18
/// </summary>
public class PageBase:System.Web.UI.Page
{
public PageBase()
{
//
//TODO: 在此处添加构造函数逻辑
//
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new System.EventHandler(PageBase_Load);
this.Error += new System.EventHandler(PageBase_Error);

}

//错误处理
protected void PageBase_Error(object sender, System.EventArgs e)
{
string errMsg = string.Empty;
Exception currentError = HttpContext.Current.Server.GetLastError();
errMsg += "<h1>系统错误:</h1><hr/>系统发生错误, " +
"该信息已被系统记录,请稍后重试或与管理员联系。<br/>" +
"错误地址: " + Request.Url.ToString() + "<br/>" +
"错误信息: " + currentError.Message.ToString() + "<hr/>" +
"<b>Stack Trace:</b><br/>" + currentError.ToString();
HttpContext.Current.Response.Write(errMsg);
Server.ClearError();
}

private void PageBase_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (HttpContext.Current.Session["username"] != null)
{
HttpContext.Current.Response.Write("搜索吧sosuo8.com登陆测试");
}
else
{
HttpContext.Current.Response.Write("你不是阿会楠,不要登陆");
}
}
}
}


具体页面

public partial class _Default :PageBase
{

protected void Page_Load(object sender, EventArgs e)
{
int ID = int.Parse(Request.QueryString["ID"]);
Response.Write("id:"+ID.ToString());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: