0

I want to serve the static images from a network shared path, but when I map this path middleware, it is throwing exception as this path cannot access in middleware. Please let me know how to map a static files from network shared folder with credentials. I am using following code

 app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(
                            Path.Combine("\\sharedfolder\images")

            }); 
Sadaqat
  • 96
  • 1
  • 9

1 Answers1

2

I got the solution from the given hint by @Stefano, thanks.

NetworkCredential sourceCredentials = new NetworkCredential { Domain = "domain", UserName = "user", Password = "pass" };

using (new NetworkConnection("\\\\networkpath\\Shared", sourceCredentials))
{
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(
                    Path.Combine("\\\\networkpath\\Shared"))
        });
    }
}
Manoj Choudhari
  • 4,636
  • 2
  • 18
  • 31
Sadaqat
  • 96
  • 1
  • 9