C# site not loading: environment variable not set

I have a ASPX C# web application that I’m trying to migrate over to a test server. The web application works perfect on my live server, but I’m running into the following error when trying to run on my test server. I copied over the project source code.

When I try to browse the site from the local machine I get the following error message (for security reasons I’m changing the name of the environment variable I’m calling it 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:SrcTfsCustomersCityTestSourceDotNetApplicationWebTestWebApplicationGlobal.asax.cs:17

First thing I did was set up that environment variable exactly how it is on my live site. Same spelling and file path. Now in my CMD if I echo out that variable I get back: C:ThisVariable

In my web.config file I found this line here:

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

In the ApplicationException error log it references a path on my D drive, but there is nothing in my D drive. I do however have a Global.asax in my project folder, but it is only one line long containing this code:
<%@ Application Codebehind="Global.asax.cs" Inherits="ThisVariable.City.Web.Application.Test.Global" Language="C#" %>

Any ideas?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Not having the full picture on whether these are user or system environmental variables, my first assumption is that these are user variables: What is the difference between user variables and system variables?

If that’s the case, then check here: IIS doesn’t use user environment variables

If you want to use user specific environment variables, then the application pool setting LoadUserProfile should be set to true (false is the default),

Otherwise, set the system variable and restart iis, or if that fails, restart the machine.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x