cdaley78
cdaley78

Reputation: 33

ASP.NET Core Error Development Mode only in Area

In Azure, I have a small app deployed: https://jsnamespace.azurewebsites.net/. In localhost, it works perfectly when navigating to localhost/Admin. However, in the deployed app, navigating to https://jsnamespace.azurewebsites.net/Admin yields an error:


Error. An error occurred while processing your request. Request ID: 0HLLGMN77UU3U:00000001

Development Mode Swapping to Development environment will display more detailed information about the error that occurred.

Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.


The source code is available publicly on GitHub: https://github.com/cdaley78/JsNamespace

I have seen other suggestions for issues like these setting ASPNETCORE_ENVIRONMENT in Azure. I feel this should not be necessary considering everything works except the code located in the Area.

What am I missing?

I have tried in Azure setting ASPNETCORE_ENVIRONMENT to "Development" in the Web App –> "Applications Settings." That makes no difference.

Upvotes: 3

Views: 2263

Answers (2)

itminus
itminus

Reputation: 25360

  1. If you set the ASPNETCORE_ENVIRONMENT=Development (and then restart the App Service), you'll find out it complains that there's no related View files found:

enter image description here

This error happens because you're setting the Admin/Home/Index.cshtml in the wrong way :

    <Compile Remove="Areas\**" />
    <Content Remove="Areas\**" />
    <EmbeddedResource Remove="Areas\**" />
    <None Remove="Areas\**" />

    ...

    <Compile Include="Areas\Admin\Controllers\HomeController.cs" />

    ...

    <None Include="Areas\Admin\Views\Home\Index.cshtml" />
  1. To fix that issue, remove those unnecessary configurations around Areas/Admin as below:
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <DebugType>full</DebugType>
  </PropertyGroup>

  <ItemGroup>
    <!-- <Compile Remove="Areas\**" />
    <Content Remove="Areas\**" />
    <EmbeddedResource Remove="Areas\**" />
    <None Remove="Areas\**" /> -->
  </ItemGroup>

  <ItemGroup>
    <Content Remove="bundleconfig.json" />
    <Content Remove="compilerconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <_ContentIncludedByDefault Remove="compilerconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <!-- <Compile Include="Areas\Admin\Controllers\HomeController.cs" /> -->
  </ItemGroup>

  <ItemGroup>
    <!-- <None Include="Areas\Admin\Views\Home\Index.cshtml" /> -->
    <None Include="bundleconfig.json" />
    <None Include="compilerconfig.json" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
    <PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Areas\Admin\Data\" />
    <Folder Include="Areas\Admin\Models\" />
  </ItemGroup>

</Project>
  1. Now it works fine for me :

enter image description here

Upvotes: 3

Vova Bilyachat
Vova Bilyachat

Reputation: 19494

Looks like that you are not using AddEnvironmentVariables. In your startup.cs you should do similar to this

var config = new ConfigurationBuilder()
    .AddEnvironmentVariables()
    .Build();

Upvotes: 1

Related Questions