简体   繁体   English

仅在区域中的ASP.NET核心错误开发模式

[英]ASP.NET Core Error Development Mode only in Area

In Azure, I have a small app deployed: https://jsnamespace.azurewebsites.net/ . 在Azure中,我部署了一个小应用程序: https : //jsnamespace.azurewebsites.net/ In localhost, it works perfectly when navigating to localhost/Admin. 在localhost中,当导航到localhost / Admin时,它可以完美地工作。 However, in the deployed app, navigating to https://jsnamespace.azurewebsites.net/Admin yields an error: 但是,在已部署的应用程序中,导航到https://jsnamespace.azurewebsites.net/Admin会产生错误:


Error. 错误。 An error occurred while processing your request. 处理您的请求时发生错误。 Request ID: 0HLLGMN77UU3U:00000001 要求编号: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. 对于本地调试,可以通过将ASPNETCORE_ENVIRONMENT环境变量设置为Development并重新启动应用程序来启用开发环境。


The source code is available publicly on GitHub: https://github.com/cdaley78/JsNamespace 源代码可在GitHub上公开获得: https : //github.com/cdaley78/JsNamespace

I have seen other suggestions for issues like these setting ASPNETCORE_ENVIRONMENT in Azure. 我已经看到了针对此类问题的其他建议,例如在Azure中设置ASPNETCORE_ENVIRONMENT。 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." 我曾尝试在Azure中将Web应用程序–>“应用程序设置”中的ASPNETCORE_ENVIRONMENT设置为“开发”。 That makes no difference. 没关系。

  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: 如果设置ASPNETCORE_ENVIRONMENT=Development (然后重新启动 App Service),则会发现它抱怨找不到相关的View文件:

在此处输入图片说明

This error happens because you're setting the Admin/Home/Index.cshtml in the wrong way : 发生此错误是因为您以错误的方式设置了Admin/Home/Index.cshtml

    <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: 要解决该问题,请删除Areas/Admin周围的那些不必要的配置,如下所示:
<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 : 现在对我来说很好:

在此处输入图片说明

Looks like that you are not using AddEnvironmentVariables . 看起来您没有使用AddEnvironmentVariables In your startup.cs you should do similar to this 在您的startup.cs您应该执行以下操作

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

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

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