Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

405 Method Not Allowed on Unknown OData Route vs 404 Not Found on REST API in .NET 8 - Is This Expected Behavior? #1300

Open
KavehRostami90 opened this issue Aug 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working P2

Comments

@KavehRostami90
Copy link

KavehRostami90 commented Aug 19, 2024

Assemblies affected
ASP.NET Core OData 8.2.5

Describe the bug
Hello,

I am working with a .NET 8 API and have encountered an issue when sending a POST request to an unknown route. Here are the details:

When I send a POST request to an OData route that doesn't exist, e.g., {{apiUrlOData}}/Locationsdd, I receive a 405 Method Not Allowed response.
However, when I send the same request to a regular REST API route that doesn't exist, e.g., {{apiUrl}}/Locationsdd, I receive a 404 Not Found response.

This difference in behavior is unexpected. It seems that OData routing might be interpreting the route in a way that leads to the 405 response instead of a 404.

Is this difference in handling unknown routes between OData and REST in .NET 8 expected? Could you please clarify why OData returns a 405 error instead of a 404, and if there is a recommended way to align these behaviors?

Request/Response
POST request to an OData route that doesn't exist, e.g., {{apiUrlOData}}/Locationsjjjjjjjj

{
"title": "Method Not Allowed",
"status": 405,
}

Expected behavior
{
"title": "Not Found",
"status": 404,
}

@KavehRostami90 KavehRostami90 added the bug Something isn't working label Aug 19, 2024
@xuzhg
Copy link
Member

xuzhg commented Aug 19, 2024

@KavehRostami90 What do you mean about "non-existed" OData route? Basically, OData route (endpoint) in 8.x is a normal ASP.NET Core endpoint containing 'OData routing metadata'. If it's an unknown route, why do you call its unknown OData route?

Would you please share a simple repro for us to dig more? Maybe a simple github repo can help us to figure out the root cause.

@julealgon
Copy link
Contributor

@xuzhg I believe he is referring to anything sitting under the root odata folder/odata prefix defined in the AddRouteComponents call.

Apparently, any invalid URL attempted under that prefix is throwing "method not allowed" instead of "not found".

Keep me honest here @KavehRostami90 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
Development

No branches or pull requests

4 participants