【问题标题】:Opening a file using impersonation使用模拟打开文件
【发布时间】:2012-09-05 23:32:05
【问题描述】:

我一直在网上搜索,以寻找一种通过模拟具有访问权限的用户从安全网络文件夹中打开 WORD 文件的方法。我最接近找到答案的是 2 年前:
Impersonating in .net (C#) & opening a file via Process.start

这是我正在使用的代码。当我设置参数 = LocalFile_Test 时,一切正常,因为用户正在访问可以访问的本地 c:\。但是当我设置 arguments = RemoteFile_Test 时,Word 会打开一个空白文档,这与我在参数中放入垃圾的效果相同。因此,即使当我使用我在下面的属性中指定的用户/域/密码登录时,它似乎也找不到该文件,我可以找到确切的文件名并且它不为空。有什么东西会立刻向你跳出来吗?感谢您的宝贵时间。

Dim LocalFile_Test As String = "C:\New.docx"
Dim RemoteFile_Test As String = "\\Server1\Apps\File\New.docx"

Dim MyStartInfo As New System.Diagnostics.ProcessStartInfo
MyStartInfo.FileName = "C:\Program Files\Microsoft Office\Office12\WINWORD.exe "
MyStartInfo.Arguments = LocalFile_Test

MyStartInfo.LoadUserProfile = True
MyStartInfo.UseShellExecute = False

MyStartInfo.UserName = "specialuser"
MyStartInfo.Domain = "mydomainname"
MyStartInfo.Password = New System.Security.SecureString()
MyStartInfo.Password.AppendChar("p"c)
MyStartInfo.Password.AppendChar("a"c)
MyStartInfo.Password.AppendChar("s"c)
MyStartInfo.Password.AppendChar("s"c)

Process.Start(MyStartInfo)

【问题讨论】:

    标签: vb.net impersonation


    【解决方案1】:

    我的理解是,您正试图从服务器获取受密码保护的文件,当您启动进程时,它只会打开一个空白的 word 文档。我认为错误是您尝试获取文件的方式,我认为您必须在服务器上映射文件的实际物理路径,例如

      System.Web.HttpContext.Current.Server.MapPath("\\Server1\Apps\File\New.docx")
    

    从那里,我相当肯定,您需要为像这样的用户创建网络凭据

      System.Net.NetworkCredential=New NetworkCredential(userName:=, password:=)
    

    最后,一旦完成,您可以写入文件,或者像这样传输文件......

        System.Web.HttpContext.Current.Response.TransmitFile(file name)
        System.Web.HttpContext.Current.Response.WriteFile(file name)
    

    然后,一旦你得到文件,你可以尝试用进程启动打开它。

    希望对您有所帮助,如果我说的不起作用,请告诉我。

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多