Dotnet cors and dotnetcors

Source: Internet
Author: User

Dotnet cors and dotnetcors

I have studied a whole. net core framework, which is quite useful and can be used in actual projects. The front-end aveon framework is also being studied;

Problem: Cross-origin, compared to the original cross-origin solution, there is still a lot of change, the original. net api only needs to be in WebApiConfig. set the cross-origin configuration in the cs file. EnableCorsAttribute ("*", "*", "*") for cross-origin activation.. net core, Startup. view the Code directly in the cs file:

Public void ConfigureServices (IServiceCollection services) {// cross-origin operation services. addCors (o => o. addPolicy ("AllowSpecificOrigin", builder => builder. allowAnyOrigin (). allowAnyMethod (). allowAnyHeader (); services. addMvc ();}

The above is cross-origin Service Registration

Public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {loggerFactory. addConsole (Configuration. getSection ("Logging"); loggerFactory. addDebug (); // cross-origin operation app. useCors ("AllowSpecificOrigin"); app. useStaticFiles (); app. useMvc (routes => {routes. mapRoute (name: "default", template: "{controller = Home}/{action = Index}/{id ?} ");});}

Cross-origin call


After the configuration is complete, it can be called at the front end, and the cross-origin request error will not be exposed again <^>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.