![](/img/trans.png)
[英]Server.MapPath does not return the right physical path mapped to a virtual directory in Web-App subfolder
[英]Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS
我創建了一個虛擬目錄“ myVirtualFile”,虛擬路徑為“ \\ myVirtualFile”,物理路徑為“ D:\\ Home \\ myProject \\ Files”
下面是我的代碼
var virtualpath="/myVirtualFile\UserManual";
var resultPath=Server.MapPath(virtualpath);
輸出是resultPath包含“ D:\\ Home \\ myProject \\ Web \\ client \\ myVirtualFile \\ UserManual”。預期輸出是“ D:\\ Home \\ myProject \\ Files”。 它返回我項目的文件夾結構。 我沒有返回虛擬目錄中提到的物理路徑。
解決了問題。 我在開發服務器上運行我的項目。從開發服務器運行到IIS的更改項目已解決。現在Server.MapPath(virtualPath)返回虛擬目錄中提到的確切物理路徑。
重新洗脫步驟
1.右鍵單擊解決方案下的啟動項目
2.單擊屬性選項
3.在右窗格中選擇Web選項
4.以前選擇了“使用Visual Studio開發服務器”單選按鈕。而不是選擇“使用本地IIS Web服務器”單選按鈕。
5.輸入項目URL作為“ http:// localhost / ApplicationNameIN_IIS ”
6.保存項目。
完成這些步驟之后。Server.MapPath(virtualPath)返回虛擬目錄中提到的確切物理路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.