Create Virtual Directory in IIS

Create the Website under IIS as shown below on port 80 so it can be accessed using http and give the appropriate hostname as required. The hostname should be available in the DNS records to access over Internet/Intranet.

Create the virtual directory as shown below. Use the default Pass-through authentication for demo purpose. You can also use Physical Path credentials on your folder if required and manage using Connect as button.

The below image shows how the Virtual Directory will look like under your website in IIS. So if you have a file saved under the Attachments folder under C:\Data\Attachments\doc1.docx, the URL to access the document will be http://mywebsite/attachments/doc1.docx. The folder can also be created on another physical drive on the same Server or can also be accessed using a UNC path.

Are you suffering from diabetes? Click here to know how you can change your life!

Create Virtual directory in Visual Studio 2017 IIS Express

You may be facing a scenario where the Images folder of your Project is hosted in another directory on your machine e.g. C:\Data\Images and not under the Project directory structure. In this case, if you need to check whether the Images are loading correctly, you’ll need to create a Virtual directory in your Web application/MVC/WebAPI Project.

Follow the below steps:

1. Right-click on your Project properties and go to the Web tab and provide the URL for the required Virtual directory and click on the button Create Virtual directory. This option edits the ApplicationHost.config file.

2. Run the application and right-click on the IIS Express icon in the status-bar notification tray. Select your website and open the config file.

3. Look for the site tag and find your website and you’ll find the Virtual directory nested tag. Edit the path and physicalPath attribute to the folder on your machine as shown below:

<site name="MyApi" id="2">                 
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\MyApi" />                 
</application>                 
<application path="/uploads" applicationPool="Clr4IntegratedAppPool">                     
<virtualDirectory path="/" physicalPath="C:\Data\Images\uploads" />                 
</application>                 
<bindings>                     
<binding protocol="http" bindingInformation="*:62216:localhost" />                 
</bindings>             
</site>

After making these changes, refresh the app to view the images in your app via localhost.

To know how to create a Virtual Directory in IIS for a website, check this post.

Show some love for the pit in my PayPal account.

Take care of your health. Click here to know more.