ASP.NET MapPath to the root of the Solution

陌路散爱 提交于 2019-12-11 12:30:14

问题


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.

I tried Server.MapPath("\Tagus.TMS.Reports/Media/VoyageControlReport.rpt") from inside the web app.

How can I get that app path?


回答1:


The Server.MapPath will use the "application level of IIS" to determine the path returned.

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.

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.

It also gives you a nice isolation for your data files (rpt) versus your runtime files (dll's).

Hope this helps,



来源:https://stackoverflow.com/questions/5002514/asp-net-mappath-to-the-root-of-the-solution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!