1

I have tried to deploy a asp.net core mvc app and a asp.net core WebApi to azure.

Both should be run on same url.

I have created a virtual directory under settings: "site\wwwroot\webapi"

And downloaded the publish settings.

I published the mvc app to:

Sitename: example

Destination URL: http://example.azurewebsites.net

The WebApi I published to:

Sitename: example/webapi

Destination URL: http://example.azurewebsites.net/webapi

But if i try to acces the URL http://example.azurewebsites.net/webapi

i get an Error 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.

kuppi
  • 53
  • 6
  • Cab you post the error message? Should be available on the cloud server. – Always Learning Feb 27 '18 at 18:06
  • The requested page cannot be accessed because the related configuration data for the page is invalid **Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'aspNetCore'** – kuppi Feb 27 '18 at 18:12
  • Is it possibly a web config inheritance issue? Can you edit your question and include the error along with the web.config for both apps? Here an SO answer that may help: https://stackoverflow.com/questions/40069806/cannot-add-duplicate-collection-entry-of-type-add-with-unique-key-attribute-n – Always Learning Feb 27 '18 at 18:23
  • Thank you that solved the Problem, but every time i republish the project the webconfig is overwritten and i only have a appsettings.json file in my Solution. – kuppi Feb 27 '18 at 19:09
  • Can you just add an empty handlers section in appsettings.json? Something like this: "Handlers": {} Another option is to have it respond to requests on a different port. – Always Learning Feb 27 '18 at 20:00

1 Answers1

2

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:

<?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:

<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.

After Publishing to Azure all worked as expected.

I found this solution on:

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

kuppi
  • 53
  • 6
  • Thanks, only thing I found that works for ASP.NET Core projects in a virtual directory – Lucas Arrefelt Apr 16 '18 at 17:11
  • Solved my problem too, thank you! Where did you find the log entry "Cannot add duplicate collection entry..."? I couldn't find it anywhere in azure app service logs. – M.R. May 23 '18 at 08:59