• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net中统一错误页面设计

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
在程序设计中,为了用户的体验,最后把程序出现的黄页错误归结到统一的页面上
下面是我在程序代码中的错误页面设计:
      它由页面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>&nbsp;&nbsp;<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>
                                            
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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());
    }
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ASP.NET中常用方法发布时间:2022-07-10
下一篇:
[转][学习]asp.net日期格式发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap