.NET Core Web API 在部署到 Azure 后无法正常工作 [英] .NET Core Web API not working after being deployed to Azure
问题描述
我有一个简单的 .NET Core Web API 应用程序,它是由 Visual Studio 在创建新项目时创建的.我想通过 FTP 将其部署到 Azure 应用服务,作为 Team Foundation Server (TFS) 2017 构建作业的一部分,这很成功:
I have a simple .NET Core Web API application—the one made by Visual Studio when a new project is created. I want to deploy it to an Azure App Service via FTP as part of a Team Foundation Server (TFS) 2017 build job, which is successful:
但是,当尝试 GET
请求时,例如以下 URL:
However, when trying a GET
request such as the following URL:
http://somerandomname.azurewebsites.net/api/values
我得到的只是一个带有文本的 404:
All I get is a 404 with the text:
您要查找的资源已被删除、名称已更改或暂时不可用.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
来自 Kudu,我收到以下错误:
From Kudu, I get the following error:
我错过了什么?
推荐答案
所以需要一个web.config.当添加新项目时,VS 2017 用一些默认值填充它并不好.使用 VS 2017 web api 默认项目,我使用右键菜单发布了它.那工作得天衣无缝.我从 Azure Web 服务中获取了 web.config 并将其集成到我自己的项目中,只更改了 dll 名称.现在,当构建作业代表 TFS 运行时,它会在通过 FTP 上传到 Azure 应用服务的文件中包含 web.config.
So a web.config is needed. The one which VS 2017 populates with some default values when a new item is added it's not good. Using a VS 2017 web api default project, I've published it using right-click menu. That worked seamlessly. I've took the web.config from Azure web service and integrated it in my own project, changing only the dll name. Now, when a build job is running on behalf of TFS, it has the web.config among the files which are uploaded via FTP to Azure app service.
这是我结束的 web.config:
Here is the web.config I've ended with:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore"/>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="dotnet" arguments=".Somerandomname.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".logsstdout" />
</system.webServer>
这篇关于.NET Core Web API 在部署到 Azure 后无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!