Error handling does not work

Asked

Viewed 212 times

0

In the config of my application I deleted the customErrors to make a test of an error that is difficult to replicate.

And where must be going the error I put a Try:

if (ModelState.IsValid)
        {
            db.TarefaHoras.Add(tarefaHora);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                ErroDetalhe erro = new ErroDetalhe();
                erro.Data = tarefaHora.Data;
                erro.UsuarioId = tarefaHora.ApplicationUserId;
                erro.JSON = JsonConvert.SerializeObject(tarefaHora);
                erro.Tipo = "TarefaHora";
                erro.Controller = "TarefaHoras";
                erro.Action = "Create Post";
                erro.Exception = ex.GetType().FullName;

                db.ErroDetalhes.Add(erro);
                db.SaveChanges();

                return RedirectToAction("ErroNaAtualizacaoDaBase", "Erros", new { id = erro.ID });                        
            }

            return RedirectToAction("Index", "Home");
        }

        ViewBag.TipoTarefaID = new CBMMSapp.DAO.TiposTarefaDAO().ListaParaDropDown();
        ViewBag.ApplicationUserId = new CBMMSapp.DAO.UsuariosDAO().ListaParaDropDown(tarefaHora.ApplicationUserId);
        ViewBag.ClienteID = new CBMMSapp.DAO.ClientesDAO().ListaParaDropDown();
        return View(tarefaHora);
    }

This error only happens at runtime and only on the Azure server, so my attempt was to get a better description of the error and for this I created a table where the information is deposited.

But....

The problem is that the Error View I am receiving is not the Erroneous View updatedwhatever base I created that is redirected in Catch.

It is the standard Aspnet Error View.

Then I went to Shared views and deleted the default page and removed the customErrors from the web.config.

And yet Azure still brings the standard Error View.

Does anyone have any idea what might be going on?

  • Remove Savechanges from inside the catch. If that’s the error, you must be having an untreated ex.

1 answer

0

Hello,

A simple way to validate having Stacktrace of your error would be to enable FREB Logs in your App Service.

FREB LOGS: Detailed information on failed requests, including a tracking of IIS components used to process the request and the time taken in each component. This can be useful if you are trying to improve the performance of the site or isolate what is causing a return of a specific HTTP error.

  • In the portal access the desired app service slot and then navigate to: Settings > Diagnostic Logs inserir a descrição da imagem aqui

  • Enable Failed request tracing option.

  • In the desired app service slot navigate to Diagnose and Solve problems
  • At the top select the Troubleshoot option and from the Tools list select FREB logs
  • A new screen will be loaded and in the list we can have access to various information, including xml with all IIS detail about the error.

For more details: https://rafaeldossantos.net/azure-failed-request-tracing-analisando-erros-de-forma-simples/

  • Hi Rafael, I’m guessing from your questions on SO that you understand English, so! I Suggest you take a read of this How not to be a spammer and then Edit your Question to Prevent it being Deleted

  • 1

    Whilst this may theoretically Answer the Question, it would be preferable to include the Essential Parts of the Answer here, and provide the link for Reference.

  • Reply edited as suggested. Thanks staff

Browser other questions tagged

You are not signed in. Login or sign up in order to post.