How to configure a different virtual directory for

2019-02-25 02:27发布

问题:

I have a c# Web Site type project which was developed in VS 2012. I want to use VS 2015 and I have trouble specifying a different virtual directory than the default root which is /.

In vs 2012, in the sln file there are these lines:

VWDPort = "59903"
VWDDynamicPort = "true"
VWDVirtualPath = "/myapp"

and everything works as expected, i.e. when the app launches in the browser it goes to: http://localhost:59903/myapp.

I opened the solution in VS 2015 and vs creates a hidden .vs folder where it puts the applicantionhost.config file under the .vs\config folder.

This is the entry it creates for the Web Site project:

<site name="My Web Application" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\costa\Documents\webapps\My Web Application" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:59903:localhost" />
    </bindings>
</site>

I tried to play with the path settings of the application and virtualDirectory elements but nothing works.

If I set the path for the application element, the web site project doesn't load. If I leave it as is and set the path of virtualDirectory to let's say /myapp I get HTTP Error 500.0 - Internal Server Error, Module: AspNetAppInitializationFailureModule, Handler: PageHandlerFactory-Integrated-4.0 or ExtensionlessUrlHandler-Integrated-4.0 depending on the url that I try to access.

If I set the paths to just "/" everything works fine.

What puzzles me is that, when I select the Web Site project in the solution explorer, in the properties window the SSL URL and URL properties are disabled. I don't know where it's getting them from. I thought the URL comes perhaps come from the applicationhost.config file.

In the web site property pages window, under Start Options, I have Start Action = Use current page, Server = Use default Web Server.

I am using VS2015 with Update 3 on a windows 2008 R2 SP1 VM (don't ask me why it's like this).

Any ideas?

I did do some research but I couldn't find anything. One other obscure thing (imo) is the ability to create sites or virtual directories in IIS express by choosing: New Web Site -> Browse -> select Local IIS on the left side. I am not too sure what this has to do with an existing web site project.

Thanks

回答1:

Having the following configuration made it work, i.e. http://localhost:59903/myapp works now as well as http://localhost:59903.

<site name="My Web Application" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\costa\Documents\webapps\My Web Application" />
    </application>
    <application path="/myapp" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\costa\Documents\webapps\My Web Application" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:59903:localhost" />
    </bindings>
</site>

Note the presence of two application elements.

See this as well: IIS7: Possible causes of 'Unrecognized configuration path' error



回答2:

There has a way that you don't need to modify the configuration file which is much easier. And this is the answer from Microsoft.

  1. In Visual Studio, on the File menu, click Open and then click Web Site.
  2. In the dialog box, click the Local IIS icon.
  3. In the top-right corner of the dialog box, click the Create New Virtual Directory button.
  4. In the Alias name text box, type the name for your virtual directory.
  5. In the Folder text box, type the fully qualified path to the physical directory where your files are located, or click the Browse button to browse to the location, and then click OK

That's it, you will be happy to see this result in your project.

https://msdn.microsoft.com/en-us/library/d6cw6cfs.aspx