IIS 上映射驱动器的 NetworkCredential 不起作用

NetworkCredential for mapped drive on IIS not working

我有一个 .net 核心 MVC 控制器,它正在从服务器上的映射驱动器下载文件。它使用 NetworkCredential 传递驱动器的用户名和密码:

[HttpGet("[Action]")]
public IActionResult PdfContract(string fileName)
{
  NetworkCredential theNetworkCredential = new NetworkCredential(_contractsUsername, _contractsPassword);
        
  CredentialCache theNetCache = new CredentialCache();
  theNetCache.Add(new Uri(_contractsPath), "Basic", theNetworkCredential);

    try
      {
        var path = _contractsPath + @"\" + fileName;
            
        if (System.IO.File.Exists(path))
          {
            return new PhysicalFileResult(path, "application/pdf");
          }
          else
          {
            return NotFound(path);
          }
        }
        catch (Exception exception)
        {
            return NotFound(exception.ToString());
        }
    }

当我 运行 它在本地 visual studio 时,这工作正常,但是当我将代码放在服务器上时,它试图使用盒子的凭据而不是我的凭据连接到驱动器我路过。有没有办法强制它使用凭据?

经过一番折腾,我找到了一种方法来做到这一点。如果其他人有这个问题,那么这个解决方案对我有用

https://www.c-sharpcorner.com/blogs/how-to-access-network-drive-using-c-sharp