Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Not able to enable CORS #5926


User avatar
0
huntethan89 created

I tried following code to enable CORS but when I'm calling api from another domain, it is still giving error-

public override void Initialize()
{
    IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

    // Enabling CORS: 
    var cors = new EnableCorsAttribute(origins: "*", headers: "*", methods: "*");
    Configuration.Modules.AbpWebApi().HttpConfiguration.EnableCors(cors);

    //Automatically creates Web API controllers for all application services of the application
    Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
        .ForAll<IApplicationService>(typeof(ProjectLearnApplicationModule).Assembly, "app")
        .Build();            

    Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));

    ConfigureSwaggerUi(); //Remove this line to disable swagger UI.
}

Do I need to make modifications at any other place? I'm using ASPNET MVC + jQuery


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    try System.Web.Http.GlobalConfiguration.Configuration.EnableCors(cors);

  • User Avatar
    0
    huntethan89 created

    Same issue

  • User Avatar
    0
    maliming created
    Support Team

    Can you use the Demo project to reproduce it? If you can, you can send the project to: [email protected]

  • User Avatar
    0
    huntethan89 created

    Is it possible that an invalid SSL certificate for Web API project could cause this issue?

  • User Avatar
    0
    maliming created
    Support Team

    You can try it with non-https