Search code examples
c#asp.net-coreroutesasp.net-core-webapicaldav

PUT Request with Attribute Routing - Error 415


I've got a PUT request from clients that looks like this:

PUT /calendars/johndoe/home/132456762153245.ics HTTP/1.1
Content-Type: text/calendar; charset=utf-8

I have a controller class setup with Attribute routing and a Method like so:

[HttpPut]
[Consumes("text/calendar")
[Route("calendars/{userName:alpha}/{calendarName:alpha}/{icsFile}")]
public async Task<ActionResult<string>> Put([FromRoute] string userName, [FromRoute] string calendarName, [FromBody] string icsFile)

        {...

I've tried different Route Attributes and a catch-all parameter but it does not work with the whole url path.

I get an error 415 response - media type unsupported

Any advice is appreciated.


Solution

  • just change your route attribute

    [Route("calendars/{userName}/{calendarName}/{icsFile}")]
    public async Task<ActionResult<string>> Put( string userName, string calendarName,  string icsFile)
    {
    ....
    }
    

    and IMHO it is better to remove [HttpPut] and [Consumes("text/calendar")]