I am implementing an ICorsPolicyProvider to dynamically determine whether or not a cross-origin request is allowed based on the route values of a GET request. When a CORS preflight request is received, the route value cannot be retrieved (GetRouteValue method returns null), probably because the corresponding route is not defined for the OPTIONS method. The HTTP method used in the actual resource request that follows the preflight request is specified in the Access-Control-Request-Method request header. Therefore, I would think it would be possible to determine the GET route and parse route values based on the request path and the value of this header, but I do not know exactly how to do this.

0

@aetos382 I'm guessing your CORS middleware is added before UseRouting. Have you tried moving UseCors after UseRouting?

0

@Kahbazi Thank you. I am calling UseRouting before UseCors. I can get route values for GET requests, but not for OPTIONS requests.

0

Repro code is here: https://github.com/aetos382/RouteValuesForOptions

I want this test to be a success. https://github.com/aetos382/RouteValuesForOptions/blob/f2c55dce70e2dd65eaba3ff91b4b566adc4e82ff/RouteValuesForOptions.Tests/MyCorsPolicyProviderTest.cs#L46-L49

0
© 2022 pullanswer.com - All rights reserved.