【问题标题】:C# site not loading: environment variable not setC# 站点未加载:未设置环境变量
【发布时间】:2021-01-07 19:51:07
【问题描述】:

我有一个 ASPX C# Web 应用程序,我正在尝试将它迁移到测试服务器。 Web 应用程序在我的实时服务器上运行良好,但在我的测试服务器上运行时遇到了以下错误。我复制了项目源代码。

当我尝试从本地计算机浏览该站点时,我收到以下错误消息(出于安全原因,我正在更改环境变量的名称,我将其称为 ThisVariable):

ThisVariable environment variable not set. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.ApplicationException: ThisVariable environment variable not set.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  


[ApplicationException: ThisVariable environment variable not set.]
   ThisVariable.Common.Configuration.BaseConfiguration.GetThisVariableHome() +203
   ThisVariable.Common.Configuration.BaseConfiguration.Initialize(String configFileName) +84
   ThisVariable.City.Web.Application.Test.Global.Application_Start(Object sender, EventArgs e) in D:\Src\Tfs\Customers\City\Test\Source\DotNet\Application\Web\TestWebApplication\Global.asax.cs:17

我做的第一件事就是准确地设置环境变量在我的实时站点上的样子。相同的拼写和文件路径。现在在我的CMD 中,如果我回显那个变量,我会返回:C:\ThisVariable

在我的web.config 文件中,我在这里找到了这一行:

<file type="log4net.Util.PatternString" value="%env{ThisVariable}\Logs\ThisVariable.City.Web.Application.Test" />

ApplicationException 错误日志中,它引用了我的 D 驱动器上的路径,但我的 D 驱动器中没有任何内容。但是,我的项目文件夹中确实有一个 Global.asax,但它只有一行包含此代码:

<%@ Application Codebehind="Global.asax.cs" Inherits="ThisVariable.City.Web.Application.Test.Global" Language="C#" %>

有什么想法吗?

【问题讨论】:

    标签: c# asp.net web-applications


    【解决方案1】:

    不知道这些是用户还是系统环境变量的全貌,我的第一个假设是这些是用户变量:What is the difference between user variables and system variables?

    如果是这样,请在此处查看:IIS doesn't use user environment variables

    如果要使用用户特定的环境变量,那么应用程序池设置LoadUserProfile应该设置为true(默认为false),

    否则,设置系统变量并重启iis,或者如果失败,重启机器。

    【讨论】:

    • 感谢您回复我。我相信它是系统变量,因为这就是它在工作现场的设置方式。我还没有重新启动 iis 或机器,所以让我试一试
    • 重新启动 IIS 修复了它。不知道我必须这样做。谢谢你的一切!
    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 2019-10-31
    • 1970-01-01
    • 2013-11-20
    • 2013-04-20
    • 2022-12-02
    • 2013-05-27
    相关资源
    最近更新 更多