【问题标题】:how to use network credential to connect share folder somewhere in the network?如何使用网络凭据连接网络中某处的共享文件夹?
【发布时间】:2021-09-21 04:37:05
【问题描述】:

这是我的代码,我想知道如何在我的代码中使用网络凭据

 string filePath = Path.Combine(@"\\192.168.5.90\uploads", newfilename);                
     using (var filestream = new FileStream(filePath, FileMode.Create,FileAccess.Write))
     {
      await uploadfile.CopyToAsync(filestream);
     }
      return Ok(newfilename); 

【问题讨论】:

  • 您将不得不模拟用户,这并非易事,并且会产生一定的安全风险。您可以考虑简单地使用mapping a network drive as a different user 来获得所需的访问权限,这不需要任何代码。

标签: c# api asp.net-core .net-core filestream


【解决方案1】:

Windows 使用运行应用进程的用户身份进行此身份验证。

您将需要模拟另一个用户并在该模拟上下文中执行写入该文件的代码。查看WindowsIdentity.RunImpersonated方法 https://docs.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.runimpersonated?view=netcore-3.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多