redirect to an error page

1

I have the following code make the connection and query the bd sql server:

public DataTable ejecutarComandoConsultar(SqlCommand varComand)
    {
        SqlDataAdapter adapatador = new SqlDataAdapter();
        DataTable tabla = new DataTable();

        try
        {
            conexionServidor.Open();
            adapatador.SelectCommand = comando;
            adapatador.Fill(tabla);
            return tabla;
        }
        catch
        {
            throw;   
        }
        finally { conexionServidor.Close(); }   
    }

What I want to do is that when there is an error in the connection, do not show the error to the user, but show him a view. I have tried adding the following in the web.config:

<system.web>
  <customErrors mode="On">
    <error statusCode="404" redirect="~/Reportes/error" />
  </customErrors>
</system.web>

but it does not work for me. thanks in advance.

    
asked by Bryan G. 13.09.2017 в 23:12
source

1 answer

1

Try changing your settings to the following:

<system.web>
  <customErrors mode="On">
    <error statusCode="404" redirect="~/Reportes/error" />
    <error statusCode="500" redirect="~/Reportes/error" />
  </customErrors>
</system.web>

Remember that the error 404 is activated when the user tries to find a resource or URL that does not exist instead the error 500 is thrown when internal errors of the server occur.

    
answered by 13.09.2017 в 23:19