简体   繁体   English

Azure虚拟目录Webdeploy之后的Asp.Net Core WebApi内部服务器错误

[英]Asp.Net Core WebApi Internal Server Error after azure virtual directory webdeploy

I have tried to deploy a asp.net core mvc app and a asp.net core WebApi to azure. 我曾尝试将asp.net核心mvc应用程序和asp.net核心WebApi部署到Azure。

Both should be run on same url. 两者都应在相同的网址上运行。

I have created a virtual directory under settings: " site\\wwwroot\\webapi " 我已经在设置下创建了一个虚拟目录:“ site \\ wwwroot \\ webapi

And downloaded the publish settings. 并下载了发布设置。

I published the mvc app to: 我将mvc应用发布到:

Sitename: example 网站名称: 示例

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

The WebApi I published to: 我将WebApi发布到:

Sitename: example/webapi 网站名称: example / webapi

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

But if i try to acces the URL http://example.azurewebsites.net/webapi 但是,如果我尝试访问URL http://example.azurewebsites.net/webapi

i get an Error 500: 我收到错误500:

The page cannot be displayed because an internal server error has occurred. 由于发生内部服务器错误,因此无法显示该页面。

I have spend several hours to find a solution, but i could not fix it. 我已经花了几个小时找到解决方案,但是我无法解决它。

I have solved the Problem. 我已经解决了问题。 I created a Web.RemoveHandlers.config file next to the Web.config file i created in my project, and set its content to: 我在项目中创建的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>

Then i edited my .csproj file and added: 然后,我编辑了.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>

After i run dotnet restore in the Package Manager Console. 在我运行dotnet restore之后,请在“程序包管理器控制台”中进行dotnet restore

After Publishing to Azure all worked as expected. 发布到Azure之后,所有工作均按预期进行。

I found this solution on: 我在以下位置找到了此解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM