asp.net中统一错误页面设计
2007-10-24 10:27
274 查看
在程序设计中,为了用户的体验,最后把程序出现的黄页错误归结到统一的页面上
下面是我在程序代码中的错误页面设计:
它由页面ErrorPage.aspx实现.
HTML代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>网站错误页面</title>
<link href="ASPNET2.0BaseCss.css" type="text/css" rel="stylesheet">
</head>
<body>
<form id="form1" runat="server">
<table cellSpacing="0" cellPadding="0" width="75%" align="center" border="0">
<TR>
<TD bgColor="#d8e4f8" colSpan="2" height="4"></TD>
</TR>
<tr>
<td vAlign="top" width="153" bgColor="#eff7f4"><asp:image id="RegisterImage" Runat="server" Width="153"></asp:image></td>
<TD align="center" bgColor="#ebebff">
<TABLE cellSpacing="4" cellPadding="0" width="580">
<TR vAlign="top" height="*">
<TD colSpan="2" height="148">
<TABLE cellSpacing="0" cellPadding="4" width="100%" border="0">
<tr>
<td><a><b>错误页:</b></a> <a><font color="red"><%=Request
["ErrorUrl"]%></font></a></td>
</tr>
<TR>
<TD>
<HR noShade SIZE="1">
</TD>
</TR>
<TR>
<td class="Normal" valign="top">
<a><b>错误信息:</b></a>
<br>
<a><font color="red"><%=Request
["ErrorMsg"]%></font></a>
</td>
</TR>
<tr>
<td height="220"></td>
</tr>
<tr>
<td vAlign="middle" align="center" height="80"><asp:button id="BackBtn"
runat="server" Width="100" CssClass="ButtonCss" Text="返回" OnClick="BackBtn_Click"></asp:button></td>
</tr>
<tr>
<td colspan="2" width="100%">
<hr size="1">
</td>
</tr>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</tr>
</table>
</form>
</body>
</html>
当应用程序发生错误时,跳转到该页,并在该页面上提示错误信息.用户单击返回按钮返回到发生错误的页面.在后置代码中这样写到:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DesktopModules_ErrorPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ //保存发生错误页面的地址,在这里如果Request.UrlReferrer.ToString()报错,就换成Convert.ToString(Request.UrlReferrer)
ViewState["BackURL"] = Request.UrlReferrer.ToString();
}
}
protected void BackBtn_Click(object sender,System.EventArgs e)
{ //返回发生错误的页面
Response.Redirect(ViewState["BackURL"].ToString());
}
}
下面是我在程序代码中的错误页面设计:
它由页面ErrorPage.aspx实现.
HTML代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>网站错误页面</title>
<link href="ASPNET2.0BaseCss.css" type="text/css" rel="stylesheet">
</head>
<body>
<form id="form1" runat="server">
<table cellSpacing="0" cellPadding="0" width="75%" align="center" border="0">
<TR>
<TD bgColor="#d8e4f8" colSpan="2" height="4"></TD>
</TR>
<tr>
<td vAlign="top" width="153" bgColor="#eff7f4"><asp:image id="RegisterImage" Runat="server" Width="153"></asp:image></td>
<TD align="center" bgColor="#ebebff">
<TABLE cellSpacing="4" cellPadding="0" width="580">
<TR vAlign="top" height="*">
<TD colSpan="2" height="148">
<TABLE cellSpacing="0" cellPadding="4" width="100%" border="0">
<tr>
<td><a><b>错误页:</b></a> <a><font color="red"><%=Request
["ErrorUrl"]%></font></a></td>
</tr>
<TR>
<TD>
<HR noShade SIZE="1">
</TD>
</TR>
<TR>
<td class="Normal" valign="top">
<a><b>错误信息:</b></a>
<br>
<a><font color="red"><%=Request
["ErrorMsg"]%></font></a>
</td>
</TR>
<tr>
<td height="220"></td>
</tr>
<tr>
<td vAlign="middle" align="center" height="80"><asp:button id="BackBtn"
runat="server" Width="100" CssClass="ButtonCss" Text="返回" OnClick="BackBtn_Click"></asp:button></td>
</tr>
<tr>
<td colspan="2" width="100%">
<hr size="1">
</td>
</tr>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</tr>
</table>
</form>
</body>
</html>
当应用程序发生错误时,跳转到该页,并在该页面上提示错误信息.用户单击返回按钮返回到发生错误的页面.在后置代码中这样写到:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DesktopModules_ErrorPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ //保存发生错误页面的地址,在这里如果Request.UrlReferrer.ToString()报错,就换成Convert.ToString(Request.UrlReferrer)
ViewState["BackURL"] = Request.UrlReferrer.ToString();
}
}
protected void BackBtn_Click(object sender,System.EventArgs e)
{ //返回发生错误的页面
Response.Redirect(ViewState["BackURL"].ToString());
}
}
相关文章推荐
- ASP.NET 页面基类设计—防止2次提交和事件统一管理
- asp.net 继承自Page实现统一页面验证与错误处理
- VS2005包加载错误,不能打开ASP.NET设计页面
- asp.net 继承自Page实现统一页面验证与错误处理
- Asp.net页面布局设计中的心得
- asp.net获取当前页面文件名,参数,域名等方法。统一session验证和权限验证的方法
- ASP.NET页面错误处理
- IIS6+asp.net 2.0+HTTP 错误 404 - 文件或目录未找到:您正在搜索的页面可能已经删除、更名或暂时不可用。
- 运行Asp.net页面过程中出现的错误及解决方案
- ASP.NET Core中显示自定义错误页面-增强版
- asp.net 中错误页面的配置问题
- ASP.NET Core应用的错误处理[1]:三种呈现错误页面的方式
- asp.net自定义错误页面
- ASP.NET 页面错误: "asp.net XML Parsing Error: no element found Line Number 1, Column 1"
- asp.net自定义错误页面
- IIS6+asp.net 2.0+HTTP 错误 404 - 文件或目录未找到:您正在搜索的页面可能已经删除、更名或暂时不可用。
- asp.net 设计中的页面流程控制的一点想法(讨论贴)
- ASP.NET定制简单的错误处理页面