I want to make an ajax call for specified address,
I add this code above my function, doesn't work
[EnableCors(origins: "*", headers: "*", methods: "*")]
public ActionResult myfunction()
{
}
thanks in advance
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Infrastructure;
namespace Nop.Web.Infrastructure
{
public class CorsPolicyStartup : INopStartup
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddCors(feature =>
feature.AddPolicy(
"CorsPolicy",
apiPolicy => apiPolicy
.AllowAnyOrigin()
//.WithOrigins("http://localhost:4200")
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(host => true)
//.AllowCredentials()
));
}
public void Configure(IApplicationBuilder application)
{
application.UseCors("CorsPolicy");
}
public int Order => 1001; //CorsPolicy should be after MVC
}
}
[EnableCors("CorsPolicy")]attribute for yours whole Controller or specific action method.