如何解决“不应为已部署的应用程序启用开发环境”?

Tia*_*nti 6 .net iis webserver azure web-deployment

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

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

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

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

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

<environmentVariables>
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>
Run Code Online (Sandbox Code Playgroud)

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

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

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

Dus*_*ush 6

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

@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>
Run Code Online (Sandbox Code Playgroud)

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

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

 <environment include="Development,Staging"> message here</environment>
Run Code Online (Sandbox Code Playgroud)

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

更多信息可以在文档中找到。

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

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