问题
Using IIS 8 on Windows 8, I've set up an application pool which runs with an identity of Network Service
.
In the code for a page, I make calls to:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Both calls return null.
I've tried combinations <identity impersonate="true|false"/>
as well as setting the Load User Profile setting to true|false in the application pool setting, but I always get a null result.
I would expect to get one of:
C:\Windows\ServiceProfiles\NetworkService\AppData\Local
C:\Windows\System32\config\systemprofile\AppData\Local
On another user's machine, they get the second folder as the path (IIS 7.5) even though the application pool runs as Network Service.
What could be happening with these profile folders?
回答1:
In your %WINDIR%\System32\inetsrv\config\applicationHost.config
look for <applicationPoolDefaults>
. Under <processModel>
, make sure you don't have setProfileEnvironment="false"
. If you do, set it to true.
回答2:
I think you need the LoadUserProfile setting as well as one additional call from a console:
cd "%~dp0" md appdata
This would create the required folder for the app pool user. I'm not sure if this will result in Environment.SpecialFolder.ApplicationData returning a correct path though.
来源:https://stackoverflow.com/questions/12056626/networkservice-under-iis-has-empty-appdata-path