当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 继承自Page实现统一页面验证与错误处理

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

红狐狸白狐狸,广西卫视大地飞歌,大染坊剧情介绍

复制代码 代码如下:

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;

/// <summary>
///first write by 李天平
///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());
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网