title: NetworkCredential for mapped drive on IIS not working
body: <p>I have a .net core MVC controller that is downloading a file from a mapped drive on a server. It uses NetworkCredential to pass the username and password for the drive:</p>
  <pre><code>[HttpGet(&quot;[Action]&quot;)]
  public IActionResult PdfContract(string fileName)
  {
    NetworkCredential theNetworkCredential = new NetworkCredential(_contractsUsername, _contractsPassword);
          
    CredentialCache theNetCache = new CredentialCache();
    theNetCache.Add(new Uri(_contractsPath), &quot;Basic&quot;, theNetworkCredential);
  
      try
        {
          var path = _contractsPath + @&quot;\&quot; + fileName;
              
          if (System.IO.File.Exists(path))
            {
              return new PhysicalFileResult(path, &quot;application/pdf&quot;);
            }
            else
            {
              return NotFound(path);
            }
          }
          catch (Exception exception)
          {
              return NotFound(exception.ToString());
          }
      }
  </code></pre>
  <p>this works fine when I run it locally in visual studio but when I put the code on the server it is trying to connect to the drive using the credentials of the box rather than those I am passing. Is there a way to force it to use the credentials?</p>