c# - azure 虚拟目录 webdeploy 后 Asp.Net Core WebApi 内部服务器错误

标签 c# azure asp.net-web-api asp.net-core asp.net-core-mvc

我尝试将 asp.net core mvc 应用程序和 asp.net core WebApi 部署到 azure。

两者都应在同一网址上运行。

我在设置下创建了一个虚拟目录: “站点\wwwroot\webapi

并下载了发布设置。

我将 mvc 应用程序发布到:

网站名称:示例

目标网址:http://example.azurewebsites.net

我发布到的 WebApi:

站点名称:example/webapi

目标网址:http://example.azurewebsites.net/webapi

但是如果我尝试访问 URL http://example.azurewebsites.net/webapi

我收到错误 500:

由于发生内部服务器错误,该页面无法显示。

我花了几个小时寻找解决方案,但无法修复它。

最佳答案

我已经解决了这个问题。我在项目中创建的 Web.config 文件旁边创建了一个 Web.RemoveHandlers.config 文件,并将其内容设置为:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <handlers xdt:Transform="Remove" />
  </system.webServer>
</configuration>

然后我编辑了 .csproj 文件并添加了:

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
</ItemGroup>

<Target Name="RemoveHandlersFromWebConfig" AfterTargets="_TransformWebConfig">
  <PropertyGroup>
    <_SourceWebConfig>$(PublishDir)Web.config</_SourceWebConfig>
    <_XdtTransform>$(MSBuildThisFileDirectory)Web.RemoveHandlers.config</_XdtTransform>
    <_TargetWebConfig>$(PublishDir)Web.config</_TargetWebConfig>
  </PropertyGroup>
  <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" />
</Target>

在包管理器控制台中运行 dotnet Restore 后。

发布到 Azure 后,一切都按预期工作。

我在以下位置找到了此解决方案:

https://github.com/nil4/xdt-samples#remove-handlers

关于c# - azure 虚拟目录 webdeploy 后 Asp.Net Core WebApi 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49015111/

相关文章:

azure - Windows Azure 访问控制和 Windows Phone 8

excel - 使用适用于 Excel/Power BI 的 Azure AD SSO 设置 Snowflake ODBC

c# - MVP,类应该在哪里创建?

c# - 遍历记录并根据条件更新数据库

sql - 将 XCODE 开发连接到 SQL Azure 数据库需要什么?

c# - 获取从授权属性调用的 api 方法的名称

c# - 如何在 ASP.NET Web API 中为 Json.NET 设置自定义 JsonSerializerSettings?

asp.net - 是否可以限制对使用 Web API 2 构建的 REST API 的访问?

c# - 处理Control +在C#中输入多行文本框

c# - 我是否必须关闭我的代码从未访问过的 HttpRequest 输入流?