星际之家

努力,执着,开拓,进取 一直在寻找自己的路
posts - 270, comments - 185, trackbacks - 9, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

basepage的异常处理

Posted on 2008-07-18 14:58 星际 阅读(48) 评论(0)  编辑 收藏 网摘
     protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            Convert.ToDateTime("afd");
        }
        catch(Exception ex)
        {
            throw ex;
        }
  
    }



protected void Page_Error()
    {
        Exception ex = Server.GetLastError();
        System.Web.HttpContext.Current.Response.Clear();
        System.Web.HttpContext.Current.Response.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head><title>");
        System.Web.HttpContext.Current.Response.Write("错误异常提示");
        System.Web.HttpContext.Current.Response.Write(" - 请速与管理员联系</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
        System.Web.HttpContext.Current.Response.Write("<style type=\"text/css\"><!-- body { margin: 20px; font-family: Tahoma, Verdana; font-size: 14px; color: #333333; background-color: #FFFFFF; }a {color: #1F4881;text-decoration: none;}--></style></head><body><div style=\"border: #cccccc solid 1px; padding: 20px; width: 500px; margin:auto\" align=\"center\">");
        System.Web.HttpContext.Current.Response.Write(ex.Message);
        System.Web.HttpContext.Current.Response.Write("</div><br /><br /><br /><div style=\"border: 0px; padding: 0px; width: 500px; margin:auto\"><strong>当前服务器时间:</strong> ");
        System.Web.HttpContext.Current.Response.Write(DateTime.Now .ToString ());
        System.Web.HttpContext.Current.Response.Write("<br /><strong>错误对象:</strong> ");
        System.Web.HttpContext.Current.Response.Write(ex.StackTrace  );
        System.Web.HttpContext.Current.Response.Write("</div></body></html>");
        System.Web.HttpContext.Current.Response.End();
        Server.ClearError();
    }

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索

China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》



相关文章:

相关链接: