James
James

Reputation: 541

Visual Studio 2015 add virtual directory

I have a web project in VS2015 (using IIS Express) and need to add a virtual directory for files that can be downloaded but are created by another process. I have added an entry to my applicationhost.config file as shown below. Whenever I start my server and go directly to a file at the location I receive a 404 in the IIS Express log.

<site name="CustomerPortal" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="C:\Dev\WebApps\CustomerPortal\src\CustomerPortal\wwwroot" />
      <virtualDirectory path="/WebReports" physicalPath="\\backup03\WebReports" />
    </application>

    <bindings>
                <binding protocol="http" bindingInformation="*:49373:localhost" />
    </bindings>
</site>

Is there something different in VS2015 to add a virtual directory like this?

I am editing the config file in my project dir/.vs/config/applicationhost.config.

Upvotes: 3

Views: 8143

Answers (3)

Tiago Freitas Leal
Tiago Freitas Leal

Reputation: 743

My problem

  • VS2015
  • Web Application with HTML file (no ASPX file)
  • single DLL on bin directory
  • bin\Resources full of js files

Html file is like this

<!DOCTYPE html>
<html>
  <head>
    <title>Wisej.SimpleDemo</title>
    <meta charset="utf-8" />
    <script src="Resources/findByQxh.js" type="text/javascript"></script>

Each js file was set to Content and Copy always and indeed it was on bin\Resources folder. But no way to get the Javascript file loaded, even after enabling the virtual directory on the {your_solution_folder}\.vs\config\applicationhost.config file.

The bin\Resources was full of js files but the \Resources folder in the project was empty, because all js files were links to files on another project.

Steps

1) Remove all the linked files from the project \Resources folder.

2) Copy all the js files to the project \Resources folder.

3) Add all js files with build action None and Do not copy

4) Remove changes to {your_solution_folder}\.vs\config\applicationhost.config to be sure this was a true solution

All went smoothly. Why?

On Web Applications the true root is the project folder, where the Web.config is. So http://localhost/Resources refers to the project \Resources folder.

Upvotes: 0

Giovanny Farto M.
Giovanny Farto M.

Reputation: 1598

For VS.Net 2015:

1.- Open the file applicationhost.config located in the following path:

{your_solution_folder}\.vs\config\

2.- Search for the tag "sites" and find the tag for the project you want to create the virtual directory.

3.- Add the following lines:

<application path="/{your_virtual_directory_name}" applicationPool="Clr4IntegratedAppPool">
   <virtualDirectory path="/" physicalPath="{your_physical_path}" />
</application>

It will be something like the following: enter image description here

Upvotes: 3

boggy
boggy

Reputation: 4027

See: Creating virtual directories in IIS express and How to configure a different virtual directory for web site project with Visual Studio 2015

The key is to add a root application (path= "/") and then your application.

Upvotes: 1

Related Questions