3

I want to update a record by calling my api endpoint using the put verb but his returns error 405 method not allowed.

My api endpoint:

app.MapPut("/sirs/{Id}", async (int Id, SIRCContext db, Sir sirc) =>
{
    var record = await db.Sirs.FindAsync(Id);

    if (record is null) 
         return Results.NotFound();

    record.ActionTaken = sirc.ActionTaken;
    record.Status = sirc.Status;
    record.ResolvedDate = sirc.ResolvedDate;
    record.FurtherActionRequired = sirc.FurtherActionRequired;
  
    await db.SaveChangesAsync();

    return Results.NoContent();
});

My client code:

public async Task UpdateSIRC(int id, Sir sirc)
{
    try
    {
        await SetAuthToken();
        var response = await _httpClient.PutAsJsonAsync($"/sirs/{id}", sirc);//Error here
        response.EnsureSuccessStatusCode();
        statusMessage = "Update Successful";
    }
    catch (Exception)
    {
        statusMessage = "Failed to update data.";
    }
}
3
  • Have you tried calling the endpoint via postman or another similar tool? Commented Jan 25, 2023 at 18:22
  • Yes, It works well on when tested on swagger Commented Jan 25, 2023 at 19:49
  • How do you create _httpClient? Commented Jan 25, 2023 at 19:55

1 Answer 1

2

I found out that adding the below to web.config works. The api was only working in debug mode and not when deployed to IIS.

<system.webServer>
  <modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
  </modules>
</system.webServer>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.