Visual Studio 2015 add virtual directory

痞子三分冷 提交于 2019-12-10 18:03:05

问题


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.


回答1:


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:




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/37869598/visual-studio-2015-add-virtual-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!