[英]How can I exclude controller name from the virtual path when I use Server.MapPath()?
在我的MVC應用程序中,我從MyController的action方法調用Server.MapPath()以生成指向存儲在名為Templates的文件夾中的特定文件的虛擬路徑:
Server.MapPath($"Templates/{pdfFileName}")
MapPath()返回如下路徑:
C:\SomePath\MyApp\MyController\Templates\MyFile.pdf
這不好,因為實際路徑應該是
C:\SomePath\MyApp\Templates\MyFile.pdf
如何獲得正確的道路? 謝謝。
嘗試使用~
:例如:
string path = Path.Combine(Server.MapPath(@"~/Templates/" + pdfFileName));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.