C#网站未加载:未设置环境变量

时间:2020-09-21 17:10:20

标签: c# asp.net web-applications

我有一个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#" %>

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

关于这些变量是用户变量还是系统环境变量,我尚无定论,我的第一个假设是这些变量是用户变量:What is the difference between user variables and system variables?

如果是这种情况,请在此处检查:IIS doesn't use user environment variables

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

否则,请设置系统变量并重新启动iis,否则,请重新启动计算机。