Method not found: when send request web api controler

Related searches

When I try to invoke api method I'm getting exception like

Method not found: 'Void System.Web.Http.Filters.HttpActionExecutedContext.set_Response(System.Net.Http.HttpResponseMessage)'.

ApiController:-

[System.Web.Http.HttpGet]
public HttpResponseMessage CheckUserAuthentication(string UserName, string Password)
{
    DomUserAuthentication objauthentication = new DomUserAuthentication();
    var res = Request.CreateResponse(HttpStatusCode.OK);
    /////Code here
    res.Content = new StringContent(json, Encoding.UTF8, "application/json");
    return res;
}

Here is my Webapi.config:-

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{Action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

Error details:-

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Method not found: 'Void System.Web.Http.Filters.HttpActionExecutedContext.set_Response(System.Net.Http.HttpResponseMessage)'.
</ExceptionMessage>
<ExceptionType>System.MissingMethodException</ExceptionType>
<StackTrace>
at SalesRevUp.CrossCutting.DataAPIErrors.OnException(HttpActionExecutedContext context) at System.Web.Http.Filters.ExceptionFilterAttribute.System.Web.Http.Filters.IExceptionFilter.ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) at System.Web.Http.ApiController.<>c__DisplayClass8.<>c__DisplayClassa.<InvokeActionWithExceptionFilters>b__6(IExceptionFilter filter) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)
</StackTrace>
</Error>

As an alternative solution, You can make use of attribute routing https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

    [Route("IntermediaryData/CheckUserAuthentication")]
    [System.Web.Http.HttpGet]
    public HttpResponseMessage CheckUserAuthentication(string UserName, string Password)
    {
        DomUserAuthentication objauthentication = new DomUserAuthentication();
        var res = Request.CreateResponse(HttpStatusCode.OK);
        /////Code here
        res.Content = new StringContent(json, Encoding.UTF8, "application/json");
        return res;
    }

404 error when send request to web api controller, 404 is "page not found". You are looking for a route that does not exist. As "j snooze" mentions, as part of the debugging of routes, try it� HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). XHR OPTIONS Check out this article, there is a section explaining the CORS setting and you can download the code and do some experiment with it. ASP.NET MVC Tooltip using Web API, Bootstrap Popover and jQuery UI dialog

You Name of Get Method is not Proper Change name from "CheckUserAuthentication" to "GetCheckUserAuthentication"

 public HttpResponseMessage GetCheckUserAuthentication(string UserName, string Password)
        {
            DomUserAuthentication objauthentication = new DomUserAuthentication();
            var res = Request.CreateResponse(HttpStatusCode.OK);
            ///////Code here
            res.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return Request.CreateResponse(HttpStatusCode.OK);
        }

Consume Web API Get method in ASP.NET MVC, Learn how to consume Web API Get method and send HTTP GET request to ASP .NET Web API Count == 0) { return NotFound(); } return Ok(students); } } NET MVC controller to get all the student records and display them in the MVC View. Attribute Routing in ASP.NET Web API 2. The order in which routes are mapped is important. Attribute route mapping config.MapHttpAttributeRoutes() must be done before convention-based routes because when the framework is matching routes in the route table, the first match wins.

If this issue still active. I found the solution. The issue was with .Net framework. I've updated from 4.6 to 4.7 and the problem was solved.

Restful Web API not working (HTTP 404 Not Found), public class AccountController : ApiController The directory or file specified does not exist on the Web server. Fidler is a proxy and has the ability to send HTTP requests but I prefer PostMan. URL looked like when it was sent by the program trying to access the WebAPI's method, at the time of the 404. ASP.NET Web API Route Controller Not Found. login/authenticate Request Method:POST Status Code:404 Not Found Remote Address:[::1]:8543 types of data for

Routing and Action Selection in ASP.NET Web API, If you create a Web API project and find that some requests don't get If you provide defaults, the route will match a URI that is missing Otherwise, if the name of the controller method starts with "Get", "Post", "Put", "Delete",� In your routing you are using an MVC Controller route, not a WebAPI route. Change your route to use MapHttpRoute instead. Here is what I put in my WebApi.config and it worked: config.Routes.MapHttpRoute( "API", "API/{action}", new { controller = "API" } );

Routing in ASP.NET Web API, NET Web API routes HTTP requests to controllers. Once a matching route is found, Web API selects the controller and the Also, note that the POST request will fail, because the controller does not define a "Post" method. The following figure illustrates the significance of Web API controller and action methods. Web API Controller Overview. If you want to write methods that do not start with an HTTP verb then you can apply the appropriate http verb attribute on the method such as HttpGet, HttpPost, HttpPut etc. same as MVC controller.

404 Not Found: The server can not find the requested resource. 405 Method Not Allowed: The request HTTP method is known by the server but has been disabled and cannot be used for that resource. 406 Not Acceptable: The server doesn’t find any content that conforms to the criteria given by the user agent in the Acccept header sent in the request.

Comments
  • Thanks for your suggestion. But not work for me!. Please suggest if any different approach.
  • Can you add entire API controller code snippet and without the core business logic
  • I have try with following test method which is also not working. Here is code details:- [System.Web.Http.HttpGet] public HttpResponseMessage GetTest() { var res = Request.CreateResponse(HttpStatusCode.OK); string json = JsonConvert.SerializeObject("ABC"); res.Content = new StringContent(json, Encoding.UTF8, "application/json"); return res; }
  • How are you calling this from Browser?