本文介绍了部署到Azure后.NET Core Web API无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的.NET Core Web API应用程序-由Visual Studio在创建新项目时创建的应用程序。我希望将其作为Team Foundation Server(TFS)2017构建工作的一部分通过FTP部署到Azure应用服务,该操作成功完成:

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:

从Kudu中,我发现以下错误:

From Kudu, I get the following error:

p>

我丢失了什么?

解决方案

因此需要一个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=".\logs\stdout" />
</system.webServer>

这篇关于部署到Azure后.NET Core Web API无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:20