在程序设计中,为了用户的体验,最后把程序出现的黄页错误归结到统一的页面上
下面是我在程序代码中的错误页面设计:
它由页面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());
}
}