.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:
但是,当尝试诸如以下 URL 的 GET
请求时:
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屋!