Sunday, August 17, 2014

A public action method 'X' was not found on controller 'Y'

Recently I've met a very strange exception in my application. A public action method 'X' was not found on controller 'Y'. After googling for a while I found that it can be when your action is marked with HttpPost or HttpGet attribute, but http method of you request doesn't fit to it. In my case my method action was marked as HttpPost and I was pretty sure that I use POST method in my request. Then I used debugger and found that HttpContext.Request.HttpMethod is equals to "GET". It was really strange. It actually means that something changes my request. I went to Web.config and found something really interesting – UrlRewrite module and bunch of rules. My request was affected by one of them, that led to redirect, and because of redirect it changed original POST http method to GET.