Page的页面验证与错误处理在asp.net中如何操作

来源:爱站网时间:2021-12-31编辑:网友分享
很多后台文件中的asp.net上都会存在一些权限的问题,遇到这些问题后要怎么让Page实现统一页面验证与错误处理呢?下面的时间,就让爱站技术频道小编给大家一一详细分析下。
复制代码 代码如下:

isAdmin();


因为当时没有用母版页去做,所以不能在母版页中统一判断权限,而当时我限于自己水平,也没有采用继承自Page这个类的方法去统一处理一些页面加载的时候都要处理的事情。现在根据“李天平(动软)”的一些代码记录下,也希望大家要学会使用继承啊!
看下一个简单的继承自Page的PageBase:

复制代码 代码如下:

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;

///

///first write by 李天平
///up by ahuinan 2009-4-18
///


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 += "

系统错误:


系统发生错误, " +
"该信息已被系统记录,请稍后重试或与管理员联系。
" +
"错误地址: " + Request.Url.ToString() + "
" +
"错误信息: " + currentError.Message.ToString() + "


" +
"Stack Trace:
" + 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("你不是阿会楠,不要登陆");
}
}
}
}
使用的时候:

Page的页面验证与错误处理在asp.net中如何操作的问题内容,小编都给大家解答清楚了,如果在操作过程中还遇到不懂的问题,可以随时来我们网站留言。

上一篇:如何编写asp.net输出文件内容代码

下一篇:如何利用System.Net.Mail传输代码邮件

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载