带有try catch块的自定义错误页面 [英] Custom error page with try catch block

查看:80
本文介绍了带有try catch块的自定义错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我已经设置了自定义错误页面,以便每当产生一些错误时,用户就会被重定向到一个自定义错误页面.但是我的问题是尽管遇到错误,系统仍未显示自定义错误页面.

这是代码

web.config文件
==================================

Hi Folks,

I have set the custom error page so that when ever some error generate then the user will be redirected to a custom error page. But my problem is that system is not showing the custom error page despite experiencing errors.

Here is the code

web.config file
===================================

<customErrors mode="On" defaultRedirect="error.aspx">
      <error statusCode="500" redirect="error.aspx"/>
      <!-- Error Page -->
      <error statusCode="400" redirect="error.aspx"/>
      <!-- ASPX Page Not Found -->
    </customErrors>




==================================
常规功能
==================================




===================================
General function
===================================

public DataSet GenerateDataset(string query)
    {
        
        if (conn.State == ConnectionState.Open)
            conn.Close();
        conn.Open();

        try
        {
            //adap = new OleDbDataAdapter(query, conn);
            adap = new OdbcDataAdapter(query, conn);
            ds = new DataSet();
            ds.Clear();
            adap.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
           
            throw ex;
            
        }
        finally
        {
            adap.Dispose();
            conn.Close();
        }
    }


=====================================
主要部分
=====================================


=======================================
Main Portion
=======================================

objGen = new GeneralFunction();
       ds = new DataSet();
       try
       {
           ds = objGen.GenerateDataset(strQuery);
           if (ds.Tables[0].Rows.Count > 0)
           {
               GridView1.DataSourceID = null;
               GridView1.DataSource = ds;
               GridView1.DataBind();
               Lbl_rc.ForeColor = System.Drawing.Color.Black;
               Lbl_rc.Font.Bold = true;
               Lbl_rc.Text = "<font color=''#009933''>Total no of unconfirm orders : " + ds.Tables[0].Rows.Count + "</font>";
               trP1.Visible = true;
               GridView1.Visible = true;


           }
           else
           {
               GridView1.DataSourceID = null;
               Lbl_rc.ForeColor = System.Drawing.Color.Black;
               Lbl_rc.Font.Bold = true;
               Lbl_rc.Text = "<font color=''#FF0000''>No unconfirm orders in the list.</font>";
               trP1.Visible = false;
               GridView1.Visible = false;

           }
       }
       catch(Exception ex)
       {

           Tabok.Visible = false;
           tab3.Visible = true;
           lblmsg.Visible = true;
           lblmsg.Text = "Error : " + ex.Message;

       }
       finally
       {

           strQuery = "";
           ds.Dispose();
           objGen = null;
       }



请让我知道上面的代码出了什么问题



Please let me know what is wrong with above code

推荐答案

此代码有很多问题,但是,特别是它会抛出一个带有500的错误页面在其中,还是其他?
There''s a ton wrong with this code, however, specifically, is it throwing the error page with a 500 in it, or something else ?


我在catch块中遇到了错误,但是我想要的是,一旦发生错误,它应该将我重定向到自定义错误页面,该错误页面目前没有发生.请提供指示
i am getting the error in catch block but what i want is when ever error occurs it should redirect me to custom error page, which is not happening currently. please provide the direction


这篇关于带有try catch块的自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆