Asp.net web api 使用Visual Studio代码将ASP.net core 2.1 WEB API部署到IIS
正在处理ASP.net core 2.1 web API项目。我需要启用API,以便我们正在开发的客户端应用程序可以访问它 到目前为止,我发现发布到IIS的唯一方法是执行手动过程:Asp.net web api 使用Visual Studio代码将ASP.net core 2.1 WEB API部署到IIS,asp.net-web-api,asp.net-core,asp.net-core-webapi,Asp.net Web Api,Asp.net Core,Asp.net Core Webapi,正在处理ASP.net core 2.1 web API项目。我需要启用API,以便我们正在开发的客户端应用程序可以访问它 到目前为止,我发现发布到IIS的唯一方法是执行手动过程: 运行dotnetpublish-c发行版 将bin\Release\netcoreapp2.1\publish\中的文件复制到我的IIS Web App文件夹中 我想知道是否有更直接的方法来做这件事 另外,构建这个版本需要相当长的时间,因此对于开发环境来说,这是一个相当缓慢的过程。问题是,在集成测试服务器上使用F
- 运行dotnetpublish-c发行版
- 将bin\Release\netcoreapp2.1\publish\中的文件复制到我的IIS Web App文件夹中
Failed to load http://localhost:86/api/shit: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8082' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
在开发此类应用程序时,启用CORS是否绝对必要
如果我这样取:
fetch(
`http://localhost:86/api/shit`,{mode: 'no-cors'}
)
我得到:
Uncaught (in promise) SyntaxError: Unexpected end of input
at eval (Pos.vue?7f37:68)
就CORs问题而言,您可以在启动时添加以下内容:
public void ConfigureServices(IServiceCollection services)
{
// Rest of config stuff ...
services.AddCors();
}
然后在中,您还需要添加以下内容
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(builder =>
{
builder.WithOrigins("http://localhost:8080",
"http://localhost:8081",
"http://localhost:8082")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
app.UseMvc();
}
这个问题是我的答案,谢谢。在我开发了我的dotnet核心webapi之后,我忘记了运行dotnet publish-c发行版,我补充说我们从VS代码迁移到了VS社区。在我看来,部署到IIS是值得的,因为您可以从GUI发布