1 Startup
public void ConfigureServices(IServiceCollection services) { services.AddCors(option => { option.AddPolicy("any", builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); }); }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCors("any"); }
2 如果部署在IIS下,web.config中还应该如下配置:
<configuration> <location path="." inheritInChildApplications="false"> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule" /> </modules> <handlers> <remove name="WebDAV" /> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\devdoc.Manager.Http.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /> </system.webServer> </location> </configuration>