1

This is my code:

[HttpPost]
public JsonResult ForgetPassword(string Email)
{
    try
    {
        throw new Exception("testing");
    }
    catch (Exception ex)
    {
        return Json("Error");
    }
}

Locally, it goes in catch block, but in IIS it doesn't go in the catch block.

  • See [ASP.NET MVC 5 error handling](https://stackoverflow.com/q/21993758/6630084) – Jackdaw May 13 '21 at 22:34
  • @Jackdaw I'm not using global error handling. All my error is handle inside the controller. – Alfred Jose May 14 '21 at 13:53
  • if its not catching what does the browser show? are you sure youre executing the post version of ForgetPassword??? – IGeoorge May 14 '21 at 23:30
  • @IGeoorge The error is "Failed to load resource: the server responded with a status of 404 ()" I added a logger in catch block and it is confirmed that catch block is not executing. – Alfred Jose May 15 '21 at 13:19

2 Answers2

0

Youll need to add the JsonRequestBehavior.AllowGet in order to get the json after post.

[HttpPost]
public JsonResult ForgetPassword(string Email)
{
    try
    {
        throw new Exception("testing");
    }
    catch (Exception ex)
    {
        return Json("Error",JsonRequestBehavior.AllowGet);
    }
}
IGeoorge
  • 140
  • 1
  • 8
0

OMG. I already found out the cause of the error.

There is a code executing before return Json("Error"); That code has an error that why the code is not reaching return Json("Error");