Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35790

Virtual directory in the project

In IIS under the site I can create a virtual directory which has a different phisical path. Can I somehow do the same in ASP.NET MVC project? Something like adding a directory which links to a different directory.

The problem is I have some folder outside the site which contains images. I added that folder in IIS under site as Dropbox, which points to completely different location:

enter image description here

Now I also use such paths in the app with Server.MapPath:

"~/Dropbox/Dev/Product/Images"

This all works when I publish in IIS. But how can I do the same locally debugging? Is there a way to add virtual directory to my project in Visual Studio?

Upvotes: 1

Views: 4494

Answers (1)

Mohsin Mehmood
Mohsin Mehmood

Reputation: 4246

I am assuming that your are running your website using IIS Express. You can find your website IIS Express configuration file by right clicking the IIS Express tray icon and then show all applications. Select your website and then click on the config path as shown in screenshot

enter image description here

In config file, find your website site element and then you can add new virtualDirectory element like this:

 <site name="Website1" id="2">
                <application path="/" applicationPool="website1">
                    <virtualDirectory path="/" physicalPath="D:\Projects/Website1" />
                    <virtualDirectory path="/Images" physicalPath="C:/Images" />
                </application>
                <bindings>
                  <binding protocol="http" bindingInformation="*:54558:localhost" />
               /bindings>
            </site>

Here you can see Images virtual directory is added.

Upvotes: 7

Related Questions