asp.net 继承自Page实现统一页面验证与错误处理
2009-04-20 00:00
1111 查看
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()); } }
相关文章推荐
- asp.net 继承自Page实现统一页面验证与错误处理
- ASP.NET Core应用的错误处理[2]:DeveloperExceptionPageMiddleware中间件如何呈现“开发者异常页面”
- ASP.NET 定制简单的错误处理页面实现代码
- ASP.NET jQuery 食谱11 (通过使用jQuery validation插件简单实现用户登录页面验证功能)
- ASP.NET jQuery 食谱12 (通过使用jQuery validation插件简单实现用户注册页面验证功能)
- ASP.NET MVC Unobtrusive JavaScript 实现 onfocusout 验证, onfocusin 清除错误
- ASP.NET定制简单的错误处理页面
- asp.net错误页面处理示例分享
- asp.net错误页面处理示例分享
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” <转>
- asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- ASP.NET定制简单的错误处理页面
- asp.net定制错误处理页面
- 统一管理页面的验证——由自定义继承Page基类想到的。
- 【Asp.Net】:如何处理大量页面的身份验证跳转
- ASP.NET页面错误处理
- ASP.NET自定义错误处理页面的添加
- ASP.NET定制简单的错误处理页面