c# - 如何使用网络凭据连接网络中某处的共享文件夹?
问题描述
这是我的代码,我想知道如何在我的代码中使用网络凭据
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);
解决方案
Windows 使用运行应用程序进程的用户的身份进行此身份验证。
您将需要模拟一个替代用户并在该模拟上下文中执行写入该文件的代码。查看WindowsIdentity.RunImpersonated
方法
https://docs.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.runimpersonated?view=netcore-3.1
推荐阅读
- selenium - 为什么 selenium webdriver 找不到元素
- python - 如何在 Python 中从 PHP API 获取文本
- image - 将现有代码更改为基于位图单色的彩色像素
- c# - 避免为异步方法重新创建事件委托
- python - 在python中复制sumif公式
- google-chrome - 无法创建 chrome 开发者帐户来发布 chrome 扩展
- mongodb - docker-compose 文件不会从专用 env 文件中获取环境变量,导致数据库播种失败
- idoc - 在 BODS 中使用 IDoc 进行数据迁移
- css - 完整的 CSS 规则作为 SCSS 中的变量
- json - 在 Interface{} 中存储配置结构并将其转换回原始结构