我想从网络共享路径提供静态图像,但是当我映射该路径中间件时,由于该路径无法在中间件中访问,它抛出了异常。请让我知道如何使用凭据从网络共享文件夹映射静态文件。 我正在使用以下代码
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine("\\sharedfolder\images")
});
答案 0 :(得分:0)
我从@Stefano给出的提示中得到了解决方案,谢谢。
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"))
});
}