AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Method HEAD is not allowed on $metadata

Open JL-Ikosoft opened this issue 4 years ago • 2 comments

Hello,

Version Microsoft.AspNetCore.OData, Version=8.0.4.0

Seems default controller doesn't allow HEAD method requests on $metadata requests: http://www.xx.com/api/<CustomerId>$metadata": The remote server returned an error: (405) Method Not Allowed.

/// <summary>
/// Represents a controller for generating OData service and metadata ($metadata) documents.
/// </summary>
public class MetadataController : ControllerBase
{
    private static readonly Version _defaultEdmxVersion = new Version(4, 0);

    /// <summary>
    /// Generates the OData $metadata document.
    /// </summary>
    /// <returns>The <see cref="IEdmModel"/> representing $metadata.</returns>
    [HttpGet]
    public IEdmModel GetMetadata()
    {
        return GetModel();
    }

I use it to make sure my customer's model is online and not to download XML.

Any reason why being so restrictive?

Kind regards

JL-Ikosoft avatar Nov 19 '21 12:11 JL-Ikosoft

@JL-Ikosoft If the built-in metadata routing can't meet you, you can build your own routing convention.

xuzhg avatar Nov 22 '21 22:11 xuzhg

Hi, did you find anything? i also have problem i latest version but in odata endpoind

services.AddControllers().AddOData(opt => opt .Count().Filter().Expand().Select().OrderBy().SetMaxTop(null) .EnableQueryFeatures() .AddRouteComponents("odata", GetEdmModel(), services => services.AddSingleton<ODataBatchHandler, DefaultODataBatchHandler>()) );

Request HTTP/1.1 HEAD http://localhost:5000/odata/ (CORS policy execution successful) but i have error "Executed endpoint '405 HTTP Method Not Supported'"

image

i also run bouth app in this same server and port image

siasty avatar Sep 07 '22 09:09 siasty

I would also be interested in a solution and have a very similar case to @siasty. If the framework doesn't offer this by default, where could I put in my own metadata routing?

JanWerder avatar Feb 13 '23 14:02 JanWerder

Ok, I seemingly solved it by using a Method Handler:

[HttpHead("odata/")]
public IActionResult MetadataHead()
{
    return Ok();
}

JanWerder avatar Feb 13 '23 15:02 JanWerder

i have solution in my repo https://github.com/siasty/Ui5_Odatav4

siasty avatar Feb 13 '23 15:02 siasty

@JanWerder I was also struggling with batch reqest they didn't have Access-Control-Expose-Headers = "OData-Version";

siasty avatar Feb 14 '23 08:02 siasty