【问题标题】:how to fix "The Development environment shouldn't be enabled for deployed applications"?如何修复“不应为已部署的应用程序启用开发环境”?
【发布时间】:2023-01-16 13:08:13
【问题描述】:

我是 .NET 框架开发人员的新手。我刚刚通过 IIS 将我的网络部署到网络服务器中,但我遇到了一些问题。我无法登录,需要显示我的数据库表的菜单没有显示。

错误。 处理您的请求时发生错误。 请求 ID:00-7ebef872d28da233400c7c5880f8e4f2-92d490fdca09490c-00

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

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

我已经更改了 web.config 中的环境变量

<environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>

我还添加了一个新的系统变量

变量名称:ASPNETCORE_ENVIRONMENT 变量值:生产

但我仍然收到错误。你能帮我解决这个问题吗?非常感谢你的帮助。

【问题讨论】:

  • 请将 ASPNETCORE_ENVIRONMENT 的值更改为 Development,而不是 Production。它不会解决问题,它会为您显示更多错误消息。它将帮助您定位问题。
  • 我之前将其设置为 Development 并出现错误,然后我试图将其更改为 Production
  • 请检查您电脑中的事件查看器。然后更新帖子中的错误详细信息。我们可以帮助你。
  • 我知道您已更改环境变量键,请更改为开发并向我们展示错误图片。
  • 谢谢你们的帮助。我试图更新计算机服务器中的数据库并且它有效。

标签: .net azure iis webserver web-deployment


【解决方案1】:

这个错误很可能与ASPNETCORE_ENVIRONMENT 无关。如果您在 Visual Studio 中使用 ASP.NET Core 模板,它将创建一个 Error.cshtml 页面。它只是来自懒惰的 Microsoft 开发人员的硬编码消息。 这是代码:

@page
@model ErrorModel
@{
  ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
   <p>
      <strong>Request ID:</strong> <code>@Model.RequestId</code>
  </p>
  <p>@Model.</p>
}

<h3>Development Mode</h3>
<p>
   Swapping to the <strong>Development</strong> environment displays detailed 
  information about the error that occurred.
</p>
<p>
    <strong>The Development environment shouldn't be enabled for deployed applications.</strong>
    It can result in displaying sensitive information from exceptions to end users.
    For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
    and restarting the app.
</p>

它从错误中实际显示的唯一内容是Request ID: 00-7ebef872d28da233400c7c5880f8e4f2-92d490fdca09490c-00。其余的根本没有用,它只是建议您切换到Development模式以查看详细的错误消息。

如果您将其发布到 IIS,请确保编辑此页面以仅在 developmentstaging 环境中正确显示错误。不要在 Production 环境中,这样面向公众的客户将不会看到您的站点错误,这些错误也可能显示敏感信息。如果您在此页面上显示错误,请将它们包含在其中

 <environment include="Development,Staging"> message here</environment>

堵塞。如果项目是 Razor 页面修改 Error.cshtml.cs 文件或 MVC 项目中的控制器。

更多信息可以在here at the doc找到。

首先使用暂存 IIS 站点,以便您可以看到实际错误。

或者使用日志记录(使用第三方日志记录提供程序,如 Serilog )到文本文件中。

【讨论】:

    猜你喜欢
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多