asp.net实现非常实用的自定义页面基类(附源码)

2019-05-22 21:58:34于海丽

2、Error.aspx

这个比较无语。通常用来提供一个有好的出错页面。对于开发人员,建议显示完整的异常信息。

下面贴一个对开发人员有帮助的页面:

(1)、设计页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Error.aspx.cs" Inherits="Error" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
 <title>出错啦</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
  <table width='100%' align='center' style='font-size: 10pt; font-family: Trebuchet MS, Arial'>
   <tr align='center'>
    <td align="center" colspan="2">
     <b>Error on page</b>
    </td>
   </tr>
   <tr>
    <td align='right' width="200">
     <b>stackTrace :</b>
    </td>
    <td align='left'>
     <asp:Label ID="lblStackTrace" runat="server"></asp:Label>
    </td>
   </tr>
   <tr>
    <td align='right'>
     <b>Error message :</b>
    </td>
    <td align='left'>
     <asp:Label ID="lblMessageError" runat="server"></asp:Label>
    </td>
   </tr>
   <tr>
    <td align='right'>
     <b>Source :</b>
    </td>
    <td align='left'>
     <asp:Label ID="lblSourceError" runat="server"></asp:Label>
    </td>
   </tr>
   <tr>
    <td align='right'>
     <b>TargetSite :</b>
    </td>
    <td align='left'>
     <asp:Label ID="lblTagetSiteError" runat="server"></asp:Label>
    </td>
   </tr>
  </table>
 </div>
 </form>
</body>
</html>

(2)、实现代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ErrorPage : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
  this.lblStackTrace.Text = this.Application["StackTrace"] as string;
  this.lblMessageError.Text = this.Application["MessageError"] as string;
  this.lblSourceError.Text = this.Application["SourceError"] as string;
  this.lblTagetSiteError.Text = this.Application["TargetSite"] as string;
 }
}

完整实例代码代码点击此处本站下载。

希望本文所述对大家asp.net程序设计有所帮助。