1

I'm developing a Xamarin.Forms application that communicates with an ASP.NET Core Web API backend. I'm encountering an issue when attempting to update an entity via a PUT request, as I consistently receive a 405 Method Not Allowed error in response.


public static async Task UpdateAsync(ExerciseType item, bool useNavigationalProperties = false)
{
    try
    {
        var json = JsonConvert.SerializeObject(item);
        var data = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await Client._httpClient.PutAsync(Client._url + $"ExerciseType/{item.ExerciseTypeId}?useNavigationalProperties={useNavigationalProperties}", data);
    }
    catch (HttpRequestException e)
    {
        Console.WriteLine($"Request error: {e.Message}");
    }
}

And here's the corresponding method in my ASP.NET Core Web API controller:

[HttpPut]
public async Task Update([FromBody] ExerciseType item, [FromQuery(Name = "useNavigationalProperties")] bool navigationalProperties)
{
    await _exerciseTypeContext.UpdateAsync(item, navigationalProperties);
}

Here is my web config


    <system.webServer>
        <handlers accessPolicy="Read, Script">
            <remove name="WebDAV" />
        </handlers>
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
        </modules>
        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, PATCH, DELETE" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>

Could someone please provide guidance on resolving this issue? Is there something I'm overlooking in my configuration or code that could be causing the problem?

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.