我在ASP.NET 2.0中模拟上下文中启动进程时遇到问题.
我在我的Web服务代码中启动了新的Process.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();
}
Run Code Online (Sandbox Code Playgroud)
"C:\ KB\GetWindowUser.exe"是包含以下代码的控制台应用程序:
static void Main(string[] args)
{
Console.WriteLine("Windows: " + WindowsIdentity.GetCurrent().Name);
}
Run Code Online (Sandbox Code Playgroud)
当我在没有模仿的情况下调用Web服务时,一切正常.
当我打开模拟时,跟随错误写入Web服务代码中的"errors"变量:
未处理的异常:System.Security.SecurityException:访问被拒绝.\ r \n\r \n在System.Security.Principal.WindowsIdentity的System.Security.Principal.WindowsIdentity.GetCurrentInternal(TokenAccessLevels desiredAccess,Boolean threadOnly)\ r \n中.GetCurrent()\ r \n在ObfuscatedMdc.Program.Main(String [] args)\ r …