Blazor无法从Publish

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

我有一个具有

PDFGenerator
组件的大风组件库。我在Blazor Server应用程序中使用此库,必须发送图像路径以将其添加到PDF中。在开发阶段,它运行良好,但是部署到测试服务器后,我由于路径而遇到了一个错误。

服务器应用程序

var Path="..\\BlazorUI\\Blazor.Components\\wwwroot\\Images\\Logo.png"
Blazor组件库:

Image image = section.Headers.Primary.AddImage(ImageSource.FromFile(path));

eRror:

System.IO.DirectoryNotFoundException:找不到路径的一部分:\ webService \ blazorui \ blazor.components \ wwwroot \ wwwroot \ images \logo.png

服务器上
Images

文件夹的路径:

C:\Webservice\application\wwwroot\_content\Blazor.Components\Images

我的问题:
如何在开发阶段和测试服务器中使用动态路径?

thanks

我做了一个临时解决方案:

var path = ""; var publishFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\_content\\Blazor.Components"); //Publish mode if (Directory.Exists(publishFolder)) { path = Path.Combine(publishFolder, restPath); } //development mode else { path = Path.Combine("..\\BlazorUI\\Blazor.Components\\wwwroot\\", restPath); } Image image = section.Footers.Primary.AddImage(ImageSource.FromFile(path));
c# asp.net-core blazor blazor-server-side
1个回答
0
投票

注 发布后:此路径是在服务器中主要应用程序文件夹的

_content/Blazor.Components/Images
中创建的。
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.