4

net core 2.0,我遇到了获取完整路径的问题,如下所示如果您有任何想法,请给我解决方案

 string filePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"), "Demopath"), "Views"), "DemoViews"), "Views.cshtml");

从这里我得到了这条路

D:\ILYAS\\nop4.0\Presentation\Nop.Web\bin\Debug\net461\Plugins\Demopath\Views\DemoViews\Views.cshtml

但我不需要\bin\Debug\net461\

因为这条额外的线我没有得到我的CSS和查看页面有人知道请告诉我

先感谢您

4

2 回答 2

3

用这个

Path.Combine(Environment.CurrentDirectory.ToString(), "Plugins", "MyDemo", "Content", "css", "style.css");

它会工作

于 2017-12-04T10:34:24.537 回答
2

路径似乎结合得当。看路径

Plugins\Demopath\Views\DemoViews\Views.cshtml

似乎合并得当。

你的问题在AppDomain.CurrentDomain.BaseDirectory

您可以使用 store url 而不是 BaseDirectory 或其他东西。

或者你可以到 Nop.Web 的根目录

或使用直接路径使用Server.MapPath("YourPath").

Server.MapPath易于多次使用Path.Combine

于 2017-12-04T09:59:17.293 回答