Why does the following problem happen?
Scenario:
- Make sure that IIS is installed
- Execute
"notepadusing admin
%WINDIR%\System32\inetsrv\config\applicationHost.config"
account
Actual Result: the file is successfully opened in notepad
-
Execute the following code in admin account’s context:
string filePath = @"%WINDIR%\System32\inetsrv\config\applicationHost.config"; Console.WriteLine(File.Exists(Environment.ExpandEnvironmentVariables(filePath)));
Actual Result: False
Expected Result: True
The problem is if you are running a 32-bit application on a 64-bit OS, the .Net framework automatically redirects the request from
%WINDIR%\System32to%WINDIR%\SysWOW64.If you change your project to target 64-bit, this will solve your problem.
You can also resolve the problem by changing System32 to sysnative, but only if you leave the application as a 32-bit app: