[英]Get full path to file while debugging using IIS Express
我有一個要調試的.NET應用程序,部分應用程序從項目中加載文件。 該文件位於
C:\Users\USER_FOLDER\Documents\Visual Studio 2012\Projects\MY_PROJECT\_templates\myFile.html
在我的代碼中,我指定了文件的相對路徑,並使用DirectoryInfo類獲取文件的完整目錄路徑:
string myFile = (new DirectoryInfo("_templates/myFile.html")).FullName;
但是,這將返回以下路徑(多余的\\作為轉義字符):
"C:\\Program Files\\IIS Express\\_templates\\myFile.html"
我期望在IIS Express中進行調試時返回的路徑與我列出的第一個路徑匹配,而不是第三個。 為什么是這樣? 我還需要在項目中設置其他內容,以使其正確導出路徑嗎? 我假設如果將代碼部署到IIS7站點上不會發生這種情況,但是我還沒有達到該測試級別。
使用Server.MapPath :
Server.MapPath("~/_templates/myFile.html")
HttpServerUtility.MapPath("~/_templates/myFile.html")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.