Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Saturday, October 15, 2022

Enable CORS in DotNet core in Startup.cs file

Browser security prevents a web page from making requests to a different domain than the one that served the web page. This restriction is called the same-origin policy. The same-origin policy prevents a malicious site from reading sensitive data from another site. Sometimes, you might want to allow other sites to make cross-origin requests to your app. Example Below  


public void ConfigureAuthentication(IServiceCollection services)

        {

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddCors(options =>

            {

                options.AddPolicy("CorsPolicy",

                    builder => builder

                    .SetIsOriginAllowed((host) => true)

                    .AllowAnyMethod()

                    .AllowAnyHeader()

                    .WithExposedHeaders("Content-Disposition")

                    .AllowCredentials());

            });

                   }