如何使用带有凭据的网络共享路径作为asp.net核心中的静态文件文件夹

问题描述 投票:2回答:1

我想从网络共享路径提供静态图像,但是当我映射此路径中间件时,它抛出异常,因为该路径无法在中间件中访问。请让我知道如何使用凭据从网络共享文件夹映射静态文件。我正在使用以下代码

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

            }); 
c# asp.net-core-2.1
1个回答
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"))
            });
        }
© www.soinside.com 2019 - 2024. All rights reserved.