c# - ASP.NET Core错误开发模式仅在Area中

标签 c# asp.net azure github asp.net-core

在Azure中,我部署了一个小应用程序:https://jsnamespace.azurewebsites.net/ 。 在 localhost 中,导航到 localhost/Admin 时它可以完美运行。 但是,在已部署的应用程序中,导航到 https://jsnamespace.azurewebsites.net/Admin产生错误:

<小时/>

错误。 处理您的请求时发生错误。 请求 ID:0HLLGMN77UU3U:00000001

开发模式 切换到开发环境将显示有关所发生错误的更详细信息。

不应在已部署的应用程序中启用开发环境,因为它可能会导致向最终用户显示异常的敏感信息。对于本地调试,可以通过将 ASPNETCORE_ENVIRONMENT 环境变量设置为 Development 并重新启动应用程序来启用开发环境。

<小时/>

源代码可在 GitHub 上公开获取: https://github.com/cdaley78/JsNamespace

我已经看到了有关在 Azure 中设置 ASPNETCORE_ENVIRONMENT 等问题的其他建议。我认为考虑到除了位于区域中的代码之外一切正常,这应该是没有必要的。

我错过了什么?

我尝试在 Azure 中将 Web App –>“应用程序设置”中的 ASPNETCORE_ENVIRONMENT 设置为“开发”。这没有什么区别。

最佳答案

  1. 如果您设置ASPNETCORE_ENVIRONMENT=Development(然后重新启动应用服务),您会发现它提示没有找到相关的查看文件:

enter image description here

发生此错误是因为您在 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" />
  • 要解决该问题,请删除 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>
    
  • 现在对我来说效果很好:
  • enter image description here

    关于c# - ASP.NET Core错误开发模式仅在Area中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55329939/

    相关文章:

    c# - 如何在不清除现有数据的情况下添加新的网格行

    caching - 新门户中我的 Azure 缓存在哪里?

    c# - 地形地面,城市中的草地和雪地 : Skylines

    c# - 检查 UWP 桌面扩展是否存在

    c# - 使用 C# TcpChannel 服务器的 Java RMI 客户端

    asp.net - 关于字符串生成器

    c# - 这段 Winform C# 代码有什么问题?它在 Windows 中运行良好,但在 mono(Linux) 中,将抛出 NullReferenceException

    c# - 未处理的 GridView 触发事件 PageIndexChanging

    azure - 使用 Azure Powershell 脚本出现错误 "Changing property ' osDisk.name' is not allowed."

    python - 使用 python 进行 Azure 共享点多重身份验证