Controller
[Route("OrderFood")]
[HttpPost]
public IHttpActionResult OrderFood(Food foodinfo)
{
//do something
...
}
[Route("ResolverError")]
public void ResolverError()
{
//Return error in a frienly and logging detail about the caller in App Insights
...
}
App_Start/RouteConfig
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "Api/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Hello, context is as follows:
My system have some calls to method OrderFood
by Postman, cause mistake so they call it with method GET. Of course, the call failed and response code 405.
So, my idea is if user request to OrderFood
with method GET, i will detect it and redirect to route ResolverError
. At here, i can manage exception and logging detail about the caller.
How about your idea? Thank you!