0

I'm create an api can upload excel file with multipart/form-data. When I run on visual studo, it work normally. But, after deploy to IIS, it can not upload and throw error as below:

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I try setting with web.config but it still not work, event api POST, GET, DELETE with json context still working normally.

1
  • Could you show us how you have your public void Configure(...) method setup? Commented Feb 23, 2020 at 3:20

1 Answer 1

1

Have a look at the docs on CORS setup in .net core

In Startup you use services.AddCors() to specify a policy e.g.

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("MyPolicy",
                builder =>
                {
                    builder.WithOrigins("http://example.com",
                                        "http://www.contoso.com");
                });
            });

            services.AddMvc();
        }
Sign up to request clarification or add additional context in comments.

3 Comments

I try and it not still not working. note: it working normally with normal api, only api upload not work
In the docs, it mentions you can use .AllowAnyHeader().AllowAnyMethod(); to the bulider, did you try this?
@user3409461 are you sure that your content-type is correct for your upload and that the file is not too large? Cors errors can sometimes mask other error messages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.