zoukankan      html  css  js  c++  java
  • 自定义错误页面

    2.建立一个页面类(假设叫BasePage),继承于Page,然后你的站点的所有页面都从这个类继承,这样你只要在BasePage类里:override OnInit事件,在里面:
    this.Error += new System.EventHandler(this.error());
    然后在error()方法里做你的统一的错误处理,这样,所有页的错误处理就一样了。

    ?
    给你点例子:
    protected void error(object sender, System.EventArgs e)
    {
    string errMsg;
    Exception currentError = Server.GetLastError();
    errMsg = "<h1>Page Error</h1><hr/>An unexpected error has occurred on this page. The system " +"administrators have been notified. Please feel free to contact us with the information " +"surrounding this error.<br/>"+
    				"The error occurred in: "+Request.Url.ToString()+"<br/>"+
    				"Error Message: <font class=\"ErrorMessage\">"+ currentError.Message.ToString() + "</font><hr/>"+
    				"<b>Stack Trace:</b><br/>"+
    				currentError.ToString();
    
    			if ( !(currentError is AppException) )
    			{
    				// It is not one of ours, so we cannot guarantee that it has been logged
    				// into the event log.
    				LogEvent( currentError.ToString(), EventLogEntryType.Error );
    			}
    
    			Response.Write( errMsg );
    			Server.ClearError();
    		}
    
  • 相关阅读:
    嗨分享-前端技术-帝国CMS手机站修改列表分页(sysShowListMorePage)
    外观模式
    模版方法模式
    原型模式(克隆)
    策略模式
    装饰模式和代理模式
    设计原则
    工厂模式
    反射机制
    vmware RHEL6.x 开启FTP和TELNET服务--root权限
  • 原文地址:https://www.cnblogs.com/King0502/p/2019417.html
Copyright © 2011-2022 走看看