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.

5
  • Cab you post the error message? Should be available on the cloud server. Commented Feb 27, 2018 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' Commented Feb 27, 2018 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: stackoverflow.com/questions/40069806/… Commented Feb 27, 2018 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. Commented Feb 27, 2018 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. Commented Feb 27, 2018 at 20:00

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, only thing I found that works for ASP.NET Core projects in a virtual directory
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.