天蓝色虚拟目录webdeploy之后的Asp.Net Core WebApi内部服务器错误

时间:2018-02-27 18:00:24

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

我尝试将 asp.net核心mvc 应用和 asp.net核心WebApi 部署到azure。

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

我在设置下创建了一个虚拟目录: “网站\ wwwroot的\的WebAPI

并下载了发布设置。

我将 mvc应用发布到:

Sitename:示例

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

我发布的WebApi:

Sitename: example / webapi

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

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

我收到错误500:

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

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

1 个答案:

答案 0 :(得分:2)

我已经解决了这个问题。我在项目中创建的Web.RemoveHandlers.config文件旁边创建了一个Web.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

相关问题