ASP.NET MapPath到解决方案的根 [英] ASP.NET MapPath to the root of the Solution
问题描述
我在选择ASP.NET应用程序中解决方案的根目录时遇到麻烦. 在此解决方案中,我有三个应用程序,一个Web应用程序,一个API和一个用于Reports的应用程序.我试图使用Server.MapPath从Web应用程序中选择我的报告"应用程序,但无法访问该文件夹.
I'm having trouble selecting the root of the solution in my ASP.NET Application. I have three applications inside this solution, a Web app, an API and an app for Reports. I was trying to select my Reports app from the Web app in code using Server.MapPath but I can't get to the folder.
我从Web应用程序内部尝试过Server.MapPath("\ Tagus.TMS.Reports/Media/VoyageControlReport.rpt").
I tried Server.MapPath("\Tagus.TMS.Reports/Media/VoyageControlReport.rpt") from inside the web app.
如何获取该应用程序路径?
How can I get that app path?
推荐答案
Server.MapPath将使用"IIS应用程序级别"来确定返回的路径.
The Server.MapPath will use the "application level of IIS" to determine the path returned.
因此返回的路径是应用程序(网站)的根的物理位置+您推送到"MapPath"方法中的所有参数.
So the path returned is the physcial location of the root of the application (web site) + what ever parameter you pushed into the "MapPath" method.
我建议您在您的网站中建立一个"/Data"目录,并使用"Server.MapPath("/Data/dataFileToTo.rpt")来获取物理路径.
I would advise you to make a "/Data" directory in your website and use the "Server.MapPath("/Data/dataFileToLoad.rpt") to get the physcial path.
它还为您的数据文件(rpt)与运行时文件(dll)提供了很好的隔离.
It also gives you a nice isolation for your data files (rpt) versus your runtime files (dll's).
希望这会有所帮助,
这篇关于ASP.NET MapPath到解决方案的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!