i'm currently building a RESTAPI in core 2.0, running it locally on my mac.
The frontend I use is a VueJS app, requesting endpoints in the API through Axios.
I use Microsoft/aspnet-api-versioning from Github to versioning my api of course.
I get a "Request failed with status code 405" in my VueJS app, and in the request i can see this: response: "{"error":{"code":"UnsupportedApiVersion","message":"The HTTP resource that matches the request URI 'http://localhost:5000/v1/auth/login' does not support the API version '1'.","innerError":null}}"
The status text is also: Method not allowed
It works just fine in Postman
I have no clue how to fix it, can't find a solution on github for the versioning.
Here is my javascript from VueJS, my controller and startup.cs file from the API.
https://gist.github.com/zyxep/99caa4ee42347352e83073b37f7b0181
fixed the problem my self.
How did you fix the problem?
+1
This response is due to a resource existing with no matching HTTP method for the specified API version. The only difference between 400 and 405 in this case is that the requested HTTP method is not supported either. The path that leads you to 405 varies between Web API and ASP.NET Core. Since the platform wasn't specified here, I can't say for sure which path it was.
If v1/auth/login maps to a controller, it seems like either the controller is not correctly configured or the client is not requesting the correct URL.
I'm happy to help if some specifics are given. If the issue is about VueJS, I'm afraid I don't know anything about that.
I got this error message while cleaning up my code. I still have no clue what I did to manage this, as I more or less only changed my Swagger documentation texts and parameter names.
The error appeared for one of three endpoints in my controller. Their routes are as follows:
At the top of the controller:
```C#
[ApiVersion( "1.6" )]
[Route( Routes.DefaultVersionedController )] // "api/v{version:apiVersion}" + "/[controller]"
1. At the top of the endpoint which does not work:
```C#
[HttpGet("{languageCode}")]
and
```C#
[HttpGet( "Check/{languageCode}" )
As of now, the only workaround I got to this error is to add text to the endpoint route. Then the first and buggy endpoint looks like the following snippet, although I don't want the AnyTextHere part in the route:
```C#
///
/// Text
///
///
/// Language code.
///
/// 200 - List
/// 400 - Bad request
/// 404 - Not found
///
[HttpGet("AnyTextHere/{languageCode}")]
[SwaggerResponse((int)HttpStatusCode.OK, Type = typeof(List
public IActionResult GetData([FromRoute] string languageCode)
{
List
try
{
myModelList= _myService.GetData(UserAccount, languageCode);
}
catch (ValidationException e)
{
Console.WriteLine(e);
throw;
}
return Ok(myModelList);
}
```
I have several controllers throughout my code, doing exactly what did not work for the first endpoint. What am I doing wrong? The endpoint is more or less a copy/paste from a working endpoint as well.
I don't see anything obvious here. I don't know what it was before so I don't really have anything to compare against. Here's the route table I see:
| URL | Status |
| ---- | ------- |
| GET api/v1.6/data/{languageCode} | 405 |
| PUT api/v1.6/data/{key} | 200, 201 |
| GET api/v1.6/data/Check/{languageCode} | 200 |
| GET api/v1.6/data/AnyTextHere/{languageCode} | 200 |
If you have more detail or, better still, the world's simplest repro, I can probably give you some more guidance.
I just solved the issue in my controller by having two route attributes like this:
namespace MyBlaBlaBla.Controllers.v1
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class PolicyController : Controller
{
[HttpGet("")]
[Route("/{pageSize}/{pageNumber}", Name = "GetAllPoliciesPaged")]
public async Task<IActionResult> GetAllPoliciesPagedAsync([FromQuery]int pageSize, [FromQuery]int pageNumber)
Most helpful comment
How did you fix the problem?