在用户凭据下从SharePoint运行外部应用程序

时间:2014-10-03 12:50:34

标签: c# sharepoint sharepoint-2010

我遇到了以下问题:我必须通过SharePoint调用外部程序并将UI外部程序的响应返回给UI。所以,我正在使用Named pipes来完成此任务:

 var startInfo = new ProcessStartInfo();
 startInfo.CreateNoWindow = false;
 startInfo.UseShellExecute = false;
 startInfo.FileName = "my.exe";
 Process.Start(startInfo);

 var response = string.Empty;
 using (var pipe = new NamedPipeServerStream("test_pipe", PipeDirection.InOut, 1, PipeTransmissionMode.Message))
 {
        pipe.WaitForConnection();

        byte[] message = Encoding.UTF8.GetBytes("Who run this?");
        pipe.Write(message, 0, message.Length);

        response = Encoding.UTF8.GetString(ReadMessage(pipe));
 }

外部程序应该通过考虑通过SharePoint触发它的用户来执行它的逻辑:

using (var pipe = new NamedPipeClientStream("test_pipe"))
{
       pipe.Connect();
       pipe.ReadMode = PipeTransmissionMode.Message;

       var whoDoneIt = System.Security.Principal.WindowsIdentity.GetCurrent().Name; // if it's called through SharePoint it'll be service account
       // perform some logic
       pipe.Write(response, 0, response.Length);
}

但它似乎是由服务帐户启动的。我的意思是,如果我使用控制台应用程序调用此外部程序,whoDoneIt变量会捕获正确的用户名(在本例中为我的),因此外部应用程序会返回正确的响应。是否有可能克服SharePoint中的这一障碍?

0 个答案:

没有答案