1

I added ELMAH to my ASP.NET MVC project and all was well. I noticed that exceptions that arise from Ajax.BeginForm (simple ajax form post) do not get logged.

When I make those same exceptions happen by calling the Controller Action directly OR doing a JQUERY $.post() ELMAH catches these exceptions.

Controller .cs

[HttpPost]
[Roles(AcctRoles.ThisRole)]
public ActionResult CreateTicket(TicketCreateViewModel ticketvm)
{            
    throw new Exception("HEY THIS IS AN AJAX ERROR. TEST.");
    return null;
}

View (ELMAH DOES NOT LOG)

@using (Ajax.BeginForm("CreateTicket", "Tickets", null, new AjaxOptions
{
    HttpMethod = "POST"
}))
{

    <div class="form-horizontal">
    Form here
    </div>
}

JQUERY (ELMAH DOES LOG)

 <button onclick="$.post('@Url.Action("CreateTicket", "Tickets")', '');">TEST EXCEPTION BUTTON</button>

When I use Fiddler or the Chrome Inspector network tab to view the response i see the normal Yellow Screen of death. When I look at the event viewer I see the standard ASP.NET warning entry.

kcabrams
  • 97
  • 2
  • 8
  • I just created a blank MVC project and copy pasted your code. The error thrown when posting the ajax form is logged in ELMAH. Can you re-create this in a sample project for me to try out? – ThomasArdal Jan 10 '19 at 08:13
  • I didn't realize there was a rich text editor on the page sending html. This is an apparent bug with elmah as seen here: https://stackoverflow.com/questions/11630435/elmah-not-logging-exceptions-for-http-post-requests-in-mvc-app-if-the-request?rq=1 – kcabrams Jan 17 '19 at 15:03
  • 1
    Maybe write an answer with that information and mark that as the correct answer? – ThomasArdal Jan 18 '19 at 06:02

1 Answers1

0

I didn't realize there was a rich text editor on the page sending html. This is an apparent bug with ELMAH as seen here: Elmah not logging exceptions for http post requests in MVC app - if the request contains XML

kcabrams
  • 97
  • 2
  • 8