2

I have an ASP.net MVC 5 aplication with VS2017. I would like to load some pictures from a network path (the pictures should not be included to the project folder structure).

I know how to add a virtual directory in IIS on my server where the application is finally running. But I dont know how to setup the same on my local computer.

On the server I can setup an Alias and a physical path.

But in my project in VS2017(properties/web) I can only press the button "create virtual directory" next to project url "http://localhost:51138/".

Can maybe someone explain how to setup an virtual directory on localhost for testing? Thank you so much.

Osti
  • 79
  • 1
  • 11

2 Answers2

2

You are using the Visual Studio Development Server which does not allow virtual directories. You can do what you want with a local copy of IIS, creating a website that points to your development folder, and creating the virtual directory you want in that website.

  1. Install a local copy of IIS. This is available to you in the Professional version of Windows.

  2. Open IIS Manager, create a new website, and set the Physical Path to your development folder.

  3. Add a binding for this website with the Host name set to a domain name you want to use for testing. I generally use ".loc" as the TLD. For example, the production website domain of "mywebservice.com" would be "mywebservice.loc". Use port 80 in the binding.

  4. Modify your local hosts file at C:\Windows\System32\drivers\etc\hosts to include this line. Replace "mywebservice.loc" with whatever domain you chose to use above
    mywebservice.loc 127.0.0.1

  5. In your VS project properties, set Web-->Servers to Use Custom Web Server and set the Server Url to mywebservice.loc or whatever domain you chose above.

Now you can add a virtual directory just as you do in production.

I do this for all my website development primarily because nothing will happen in production that does not happen locally. You can even test using real SSL certificates this way.

sthames42
  • 888
  • 8
  • 19
2

Just create a folder in the directory of your project to mimic what will be a virtual directory and then copy some test files there.

For example, create a documents directory in your project directory. So the referenced path in your project will be something like ~/documents/somefile.pdf

The server's virtual directory documents can then point to some some other network location.

colinD
  • 1,641
  • 1
  • 20
  • 22
Jason G.
  • 21
  • 1