You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CORS preflight doesn't work with OData in ASP.NET Core #1611
Sending CORS preflight requests to an OData service running on ASP.NET Core fails with 404 when it shouldn't. Note that this is a different symptom than this similar issue, and also likely a different cause since the implementation of CORS in ASP.NET Core is substantially different than the one for classic ASP.NET.
Assemblies affected
Microsoft.AspNetCore.OData 7.0.1
Reproduce steps
I managed to reproduce this by creating a solution with two projects: One ASP.NET Core Web API project, and one MSTest-based unit test project. For some reason, I couldn't get ASP.NET Core to work at all if I combined all the code in a single project.
I have done a local test where I've set the method to whatever is passed in the Access-Allow-Control-Method header, and then the result will be status code 200 (although I suppose it should actually be 204). Inserted at L83 of WebApiRequestMessage:
I wish there was a way I could just say "See that OPTIONS header and just return OK" as CORS is a blight on the internet.
All it does is force all clients to hit the servers twice since there's literally no way to verify the information in the request is valid it boils down to trusting the client to tell you they care about this and are giving you the right information. Much like the EU cookie directive ... this feature needs to die!
Rant over ... In the meantime ...
I would like a way to do something like "app.UseCors().AllowAnything()" and just have any request from any browser accept that all OPTIONS request have come back positive regardless.
Right now the only way I know of to get this behavior is to literally put in custom middle-ware to look for the OPTIONS header and respond then end the request but that's an ugly hack.
Still doesn't work for me.
In Preflight "OPTIONS" I get 405 with a header: "allow: DELETE, GET, PATCH"
Tried to remove "app.UseCors()", the same thing.
In the logs I see:
"No CORS policy found for the specified request." (this is with app.UseCors())
or just:
"Executing endpoint '405 HTTP Method Not Supported'" (this is without app.UseCors())
Activity
cornem commentedon Sep 28, 2018
Related to aspnet/CORS#98?
A possible workaround is to let middleware handle the CORS pre-flight requests (but it means less granular control over CORS policies):
And adding
app.UseCors()before the call toUseMvc().The
ODataRequestMethodenum doesn't knowOptions, soUnkownis returned here. As a resultEntitySetRoutingConventiondoesn't find a matching action.I have done a local test where I've set the method to whatever is passed in the
Access-Allow-Control-Methodheader, and then the result will be status code200(although I suppose it should actually be204). Inserted at L83 of WebApiRequestMessage:JoshZA commentedon Feb 2, 2019
👍
TehWardy commentedon Jul 15, 2019
Tell me about it ...
I wish there was a way I could just say "See that OPTIONS header and just return OK" as CORS is a blight on the internet.
All it does is force all clients to hit the servers twice since there's literally no way to verify the information in the request is valid it boils down to trusting the client to tell you they care about this and are giving you the right information. Much like the EU cookie directive ... this feature needs to die!
Rant over ... In the meantime ...
I would like a way to do something like "app.UseCors().AllowAnything()" and just have any request from any browser accept that all OPTIONS request have come back positive regardless.
Right now the only way I know of to get this behavior is to literally put in custom middle-ware to look for the OPTIONS header and respond then end the request but that's an ugly hack.
marabooy commentedon Oct 1, 2020
Closing this as a it is fixed now.
sherlock1982 commentedon Mar 29, 2022
Still doesn't work for me.
In Preflight "OPTIONS" I get 405 with a header: "allow: DELETE, GET, PATCH"
Tried to remove "app.UseCors()", the same thing.
In the logs I see:
"No CORS policy found for the specified request." (this is with app.UseCors())
or just:
"Executing endpoint '405 HTTP Method Not Supported'" (this is without app.UseCors())