throwing/returning a 404 actionresult or exception in Asp.net MVC and letting IIS handle it

ASP.NET MVC 3 introduced the HttpNotFoundResult action result which should be used in preference to manually throwing the exception with the http status code.
This can also be returned via the Controller.HttpNotFound method on the controller:

public ActionResult MyControllerAction()
{
   ...

   if (someNotFoundCondition)
   {
       return HttpNotFound();
   }
}

Prior to MVC 3 you had to do the following:

throw new HttpException(404, "HTTP/1.1 404 Not Found");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)