简体   繁体   中英

Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS

I have created a virtual directory "myVirtualFile" virtual path is "\\myVirtualFile" and I have given physical path as "D:\\Home\\myProject\\Files"

Below is my code

var virtualpath="/myVirtualFile\UserManual";
var resultPath=Server.MapPath(virtualpath);

out put is resultPath contains "D:\\Home\\myProject\\Web\\client\\myVirtualFile\\UserManual" Expected out put is "D:\\Home\\myProject\\Files". It returns the folder structure of my project. I didn't return the physical path which I mentioned in virtual directory.

Resolved the issue. I was running my project in development server.Changed project running from development server to IIS issue resolved.now the Server.MapPath(virtualPath) returns the exact physical path mentioned in Virtual directory.

Reselution steps

1.Right click the start up project under solution

2.Click properties option

3.Select web option in the right pane

4.Previously "Use Visual Studio Development server" Radio button was selected.Instead of this select "Use Local IIS Web server" Radio button.

5.Enter project URL as " http://localhost/ApplicationNameIN_IIS "

6.Save the project.

After these steps done.Server.MapPath(virtualPath) Returns the exact physical path mentioned in the virtual directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM