locked
Enable CORS is not working after publishing into IIS RRS feed

  • Question

  • User-1783978083 posted

    I hosted dotnet core 2.2 web api application to local IIS. When i run hosted site, site is working. I am trying to do login from angular, it is not working.

    It says Access to XMLHttpRequest at 'http://192.168.43.143:100/Auth/Login' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    Note: It was working locally. No CORS policy issue occured

    I have added cors policy in ConfigureServices and provide middleware to add UseCors().

    public void ConfigureServices(IServiceCollection services)
    {
       services.AddCors(c =>  
                {    
                    c.AddPolicy("AllowOrigin", options => options.AllowAnyHeader()
                        .AllowAnyMethod().AllowAnyOrigin()
                        .SetIsOriginAllowed((host) => true).AllowCredentials());  
                });
    
       services.Configure<MvcOptions>(options => {
                    options.Filters.Add(new CorsAuthorizationFilterFactory("AllowOrigin"));
                });
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseCors("AllowOrigin");
        app.UseMvc();
    }
    

    My installed software details are given below,

    • System: Windows 10
    • DotNet Core SDK: 2.2.110 & 3.1.201
    • Windows Server Hosting: 2.2.1
    Sunday, July 12, 2020 1:29 PM

All replies

  • User-474980206 posted

    You should use the browser network trace to see the actual response. It’s probably an error message.

    Sunday, July 12, 2020 3:45 PM
  • User-1783978083 posted

    Could you please elaborate details? How can i check it?

    Sunday, July 12, 2020 5:32 PM
  • User-2054057000 posted

    In local there is no need for CORS. 

    You have not properly configured CORS in your project. Check the settings once again - 

    How to Enable Cross-Origin Requests (CORS) in ASP.NET Core

    Sunday, July 12, 2020 5:41 PM
  • User-1783978083 posted

    I done the same thing to my project. I already mentioned Cors setup to my project. Still i faced the problem

    Sunday, July 12, 2020 5:45 PM