对应用程序进行身份验证以写入服务器上的文件 [英] Give authentication to application to write to file on server

查看:79
本文介绍了对应用程序进行身份验证以写入服务器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个Web应用程序,该应用程序应该在服务器上的文件夹中创建并保存文件.我发现,只有在打开该文件夹中所有人"的安全凭证后,它才起作用. Windows是否应该具有一个专门用于此类Web应用程序的内置用户帐户,是否有一种方法可以使该应用程序使用允许写入文件夹的凭据来运行脚本?

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?

推荐答案

您正在寻找IIS_USR帐户. http://learn.iis.net /page.aspx/140/understanding-built-in-user-and-group-accounts-in-iis/ [应用程序池标识 [
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[^]


不要添加所有人以确保文件夹安全.
而是将网络服务"和"ASP NET帐户"添加到安全性中.并授予修改"访问权限.
Do not add "Everyone" to folder security.
Instead add "Network services" and "ASP NET account" to security. and give "Modify" access permission.



使用此方法
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


这篇关于对应用程序进行身份验证以写入服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆