1

I've been trying find a solution about 405 method not allowed problem. There is an api for login and register. Register post method works fine but when i send credentials from postman i get 405 error. I've searched solution and <remove name="WebDAVModule" /> is very widely answer but it doesn't solve my problem. How can i fix it ?

CreateUser works fine.

   [HttpPost]
        [Route("CreateUser")]
        public async Task<IActionResult> CreateUser([FromBody]RegisterVm register)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var userIdentity = _mapper.Map<User>(register);
            var result = await _userBusiness.CreateUser(userIdentity, register.Password).ConfigureAwait(true);
            if (!result.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState));

            return new OkObjectResult("Account created");
        }

Login doesn't work.

[HttpPost]
    [Route("Login")]
    public async Task<IActionResult> Login([FromBody]LoginVm login)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var identity = await GetClaimsIdentity(login.Email, login.Password);
        if (identity == null)
        {
            return BadRequest(Errors.AddErrorToModelState("login_failure", "Invalid username or password.", ModelState));
        }

        var jwt = await Tokens.GenerateJwt(identity, _jwtFactory, login.Email, _jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented }).ConfigureAwait(true);
        return new OkObjectResult(jwt);
    }
Guillaume S.
  • 1,515
  • 1
  • 8
  • 21
Trinity
  • 486
  • 8
  • 27
  • You can refer to my answer [here](https://stackoverflow.com/questions/30346907/how-to-remove-webdav-module-from-iis/65647298#65647298) – Rickless Jan 09 '21 at 20:32

1 Answers1

1

Honestly, only two reasons for this:

  1. The user agent is accidentally sending an incorrect HTTP method.
  2. The server is expecting only a handful of valid HTTP methods for the requested resource which don't include what you need.

Since 2 is obviously not the answer, you need to make sure that your caller is actually POSTING data, instead of using GET, PUT, DELETE or any other verb.

Microsoft documentation for debugging and resolving this: https://learn.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61