GithubHelp home page GithubHelp logo

Attribute doesn't work with UseCors about cors HOT 5 CLOSED

aspnet avatar aspnet commented on August 30, 2024
Attribute doesn't work with UseCors

from cors.

Comments (5)

jbagga avatar jbagga commented on August 30, 2024 1

CORS can be a little tricky. This may be because you are applying a more restrictive policy UseCors("OtherPolicy") and then trying to use a more relaxed version EnableCors("AllowAll"). If you wish some controller's actions to be specifically available to a certain origin, apply the more specific policy as an attribute to that controller. Also, when using MVC and CORS, it is recommended you use this example as a guideline.

Please let me know if the issue is something else. Maybe share your sample application or use the sample in the CORS repository to try your scenario.

from cors.

wparad avatar wparad commented on August 30, 2024

At your link it says

The precedence order is: Action, controller, global. Action-level policies take precedence over controller-level policies, and controller-level policies take precedence over global policies.

Which directly contradicts what you just said, it seems that documents don't represent the reality, which is "the order of applied policies is global, controller, and then action"

from cors.

dougbu avatar dougbu commented on August 30, 2024

@wparad running the action policies last means they can override (i.e. have precedence over) all other policies. What exactly is incorrect in the documentation?

from cors.

jbagga avatar jbagga commented on August 30, 2024

@wparad Thank you for your response. My apologies. My comment before is not descriptive enough. So, when using UseCors() middleware logic for Cors runs. This is a completely different middleware than MVC. If you read the example again, it says

When using MVC to enable CORS the same CORS services are used, but the CORS middleware is not.

and

You can enable CORS globally for all controllers by adding the CorsAuthorizationFilterFactory filter to the global filter collection

You are recommended to use CorsAuthorizationFilterFactory to set a global CORS policy for your controllers in MvcOptions.

This should solve the problem. But let us know if it doesn't work!

from cors.

wparad avatar wparad commented on August 30, 2024

Thanks @jbagga for the clarifications, let's close the issue for now.

from cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.