I my asp.net application,I have to read some file in the system32 directory.
Like
c:/windows/system32/xx.config.
But I always get the "FileNotFound" exception.
It seems that this is related to the permission problem
How to solve it?
Update
XmlDocument doc=new XmlDocument();
string file = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config\\applicationHost.config";
string dir = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config";
log.Info(Directory.Exists(dir)); // ==> true
log.Info(File.Exists(dir+"\\applicationHost.config")); // ==> false
if(File.Exist(file))
doc.load(file);
Even I change the System
to SystemX86
,the result does not change.
Then I load the file directly without check its exist:
XmlDocument doc=new XmlDocument();
string file = Environment.GetFolderPath(Environment.SpecialFolder.System) +"\\inetsrv\\config\\applicationHost.config";
doc.load(file);
Then I got this:
Access to path "C:\Windows\System32\inetsrv\config\applicationHost.config" is denied.
It seems that the file is protected,so I try to add all the permissions(read/execute/write) for user "NetWorkService" for Both the file and its parent folder.
But the Exception is still throwed.
C:\Windows\system32\intesrv\config
because my system was 64 bit and my request redirect toC:\Windows\SysWOW64\system32\intesrv\config
More explanation is given by [this answer](https://stackoverflow.com/a/23327624/2674033). PS. My answer is left here just for those who will be in search in future – Barabas Mar 03 '18 at 03:07