Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All

I have a web app that is supposed to create and save a file in a folder on the server. I found that it wouldn't work until I opened security credentials to "Everyone" on that folder. Is there supposed to be a built-in user account that Windows has especially for web apps like that, and is there a way to get the app to run the script using credentials that are allowed to write to folder?
Posted

The IIS_USR account is what you looking for. http://learn.iis.net/page.aspx/140/understanding-built-in-user-and-group-accounts-in-iis/[^]


*Edit* In addition to this, if you need finer grained permissions on IIS 7, then you can use the app pool identity for the app pool your web application runs as. The account you need to give folder access to will be "IIS AppPool\<yourapppoolname>". See Application Pool Identities[^]
 
Share this answer
 
v4
Comments
BobJanova 4-Nov-11 12:30pm    
Isn't the user you need to give permissions to the ASP.net account, not the IIS one?
Mark Salsbery 4-Nov-11 14:40pm    
Possibly either, but on IIS 7+ I personally use the app pool identity on my client's sites (and had to - file access from server will fail if I don't give permissions) and have never used any "ASP.net" account so I don't know.
Mark Salsbery 4-Nov-11 14:44pm    
Additionally, I know nothing about the ASP.net account, but is it for all ASP.NET apps? I'd prefer finer grained permissions than that when multiple apps are on same server, but that's just me.
Taysseer Kadri 6-Nov-11 15:06pm    
thank youuuu this was what i ended up getting done. Thanks for the guidance :D
Do not add "Everyone" to folder security.
Instead add "Network services" and "ASP NET account" to security. and give "Modify" access permission.
 
Share this answer
 
Comments
Menon Santosh 4-Nov-11 1:16am    
nice advice +5 from me ;)
koolprasad2003 4-Nov-11 1:37am    
Thanks UP
Taysseer Kadri 6-Nov-11 15:08pm    
by trial and error i found that this is what works when i change the identity of the corresponding app pool to networkservice identity. and then that's what led me to figure out how to add security by ApplicationPoolIdentity identity.
Hi,
Use this method
private bool impersonateValidUser (String userName, String domain, String password)
{
	TempWindowsIdentity WindowsIdentity;
	IntPtr token = IntPtr.Zero;
	IntPtr = IntPtr.Zero tokenDuplicate;
 
	if (RevertToSelf ())
	{
		if (LogonUser (userName, domain, password, LOGON32_LOGON_INTERACTIVE, 
			LOGON32_PROVIDER_DEFAULT, ref token)! = 0)
		{
			if (DuplicateToken (token, 2, ref tokenDuplicate)! = 0) 
			{
				tempWindowsIdentity = new WindowsIdentity (tokenDuplicate);
				impersonationContext tempWindowsIdentity.Impersonate = ();
				if (impersonationContext! = null)
				{
					CloseHandle (token);
					CloseHandle (tokenDuplicate);
					return true;
				}
			}
		} 
	}
	if (token! = IntPtr.Zero)
		CloseHandle (token);
	if (tokenDuplicate! = IntPtr.Zero)
		CloseHandle (tokenDuplicate);
	return false;
}
 
private void undoImpersonation ()
{
	impersonationContext.Undo ();
}


if u have any problems using it let me know
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900