Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7.5 application pool uses wrong %APPDATA% for custom user as identity

I want my MVC3 web application to access %APPDATA% (e.g. C:\Users\MyUsername\AppData\Roaming on Windows 7) because I store configuration files there. Therefore I created an application pool in IIS with the identity of the user "MyUsername", created that user's profile by logging in with the account, and turned on the option "Load User Profile" (was true by default anyway). Impersonation is turned off.

Now I have the problem that %APPDATA% (in C#):

appdataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

resolves to c:\windows\system32\inetsrv instead of C:\Users\MyUsername\AppData\Roaming.

UPDATE: More exactly, the above C# code returns an empty string, so that Path.GetFullPath(Path.Combine(appdataDir, "MyAppName")) prepends the current path to my application name, resulting in c:\windows\system32\inetsrv\MyAppName.

I know I made this work before with the same web application on a Windows Server 2008 R2, and now I'm getting this problem with the same major version 7.5 of IIS on my Windows 7.
I used the same procedure as before: Created a new user, logged in as that user to create the profile and APPDATA directories, then added the application pool with this identity and finally added the web application to this pool.

Any ideas?

like image 344
AndiDog Avatar asked Feb 28 '12 21:02

AndiDog


People also ask

What is the default identity of an application pool?

For every application pool you create, the Identity property of the new application pool is set to ApplicationPoolIdentity by default. The IIS Admin Process (WAS) will create a virtual account with the name of the new application pool and run the application pool's worker processes under this account by default.

How do I give application pool identity permissions to a folder?

Click the Locations button and make sure that you select your computer. Enter IIS AppPool\<myappoolname> (eg: IIS AppPool\PK Protect) in the Enter the object names to select: text box. Click the Check Names button and click OK. Check Modify under the Allow column, and click OK, and OK.

How do I change my application pool account?

You can change which user account is being used by right clicking “Application Pool” > Advanced Settings > Under “Identity”, you can click the “…” and look for a different user account. You can either choose any of the service accounts on the server, or choose a specific user to run a specific application.


1 Answers

I experienced the same problem recently. As mentioned by Amit, the problem is that the user profile isn't loaded. The setting is for all application pools, and is in the applicationHost.config (typically C:\Windows\System32\inetsrv\config\applicationHost.config). If you update the applicationPoolDefaults elements as follows, it will work;

<applicationPoolDefaults managedRuntimeVersion="v4.0">
  <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</applicationPoolDefaults>

We've tried this with IIS 7.5, and taken it through to production without problem.

You can automate this if you want;

appcmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.processModel.setProfileEnvironment:"true" /commit:apphost

or if you prefer powershell

Set-WebConfigurationProperty "/system.applicationHost/applicationPools/applicationPoolDefaults/processModel" -PSPath IIS:\ -Name "setProfileEnvironment" -Value "true"

Hope this helps

like image 88
tapmantwo Avatar answered Sep 22 '22 22:09

tapmantwo