题
我有在ASP.NET 2.0开始在模拟上下文处理问题。
我在我的web服务代码开始新的进程。 IIS 5.1,.NET 2.0
[WebMethod]
public string HelloWorld()
{
string path = @"C:\KB\GetWindowUser.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = Path.GetDirectoryName(path);
startInfo.FileName = path;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
Process docCreateProcess = Process.Start(startInfo);
string errors = docCreateProcess.StandardError.ReadToEnd();
string output = docCreateProcess.StandardOutput.ReadToEnd();
}
在 “C:\ KB \ GetWindowUser.exe” 是包含以下代码控制台应用程序:
static void Main(string[] args)
{
Console.WriteLine("Windows: " + WindowsIdentity.GetCurrent().Name);
}
当我调用Web服务而不模仿,一切工作正常。
当我打开模拟,以下错误写入的“错误”的web服务代码变量:
未处理的异常信息:System.Security.SecurityException:访问被拒绝\ r \ n \ r \ n在System.Security.Principal.WindowsIdentity.GetCurrentInternal(TokenAccessLevels desiredAccess,布尔threadOnly个)\ r \ n在System.Security。 Principal.WindowsIdentity.GetCurrent(个)\ r \ n在ObfuscatedMdc.Program.Main(字串[] args)\ r \ n该失败的组件的区域是:\ r \ nMyComputer
模拟的用户是本地管理员,并已获得C:\ KB \ GetWindowUser.exe可执行
当我在ProcesStartInfo属性域,用户和密码明确指定窗口的用户,我得到以下信息: http://img201.imageshack.us/img201/5870/pstartah8.jpg
是否有可能与来自asp.net不同凭证比ASPNET(IIS 5.1)?
启动过程解决方案
您必须把特权代码到GAC(或在完全信任运行)。
在GAC代码必须断言XXXPermission,其中XXX为你请求什么都允许,无论是模拟,进入硬盘或者你有什么。
您应该恢复断言立即后记。
您应该确保你把在GAC你的DLL原料药有没有滥用的机会。例如,如果你在写的通过命令行应用程序让用户备份服务器的网站时,你的API应该老公开的方法,如“备份()”而不是“LaunchAribitraryProcess(字符串路径)”
在web.config文件中必须有模拟设置好了,否则你会遇到NTFS权限问题以及CAS。
下面是完整的解释。
其他提示
您也可以尝试包装内
你的代码using (Impersonator person = new Impersonator("domainName", "userName",
"password")
{
// do something requiring special permissions
}
如在提及 http://www.devnewsgroups.net/group/ microsoft.public.dotnet.framework.windowsforms / topic62740.aspx
究竟是什么你想怎么办?我不能完全明白你的代码的点是在创建一个不同的可执行文件。它看起来相当奇怪。也许它会更有助于说明你正试图首先要解决的业务内容的问题。
它看起来像你想有IIS服务模拟用户比服务本身(在这种情况下,管理员)更高的权限。 Windows阻止这是一个安全漏洞,因为在这一点上你基本上乞求别人接管您的系统。有可能是解决这一限制的一种方式,但不这样做 - 这是为你自己好
相反,有IIS模拟与有限的权限,谁拥有正是你需要它有权限的用户。例如。创建仅拥有你希望你的Web服务写入,或任何权利的其他组合是合适的文件夹的用户帐户。如果假冒有限的用户,您将不会看到此错误代码,但仍然应该能够给你打电话这里有良性的可执行文件。