Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Visual Studio from modifying the IIS Express site's phyical path in applicationhost.config?

I have a Visual Studio web application project that, for certain reasons, copies files from multiple projects to a separate output directory. I want to use this output directory as the root of the associated IIS Express site. In IIS Express' applicationhost.config file, I can set the associated site's physical path to the correct directory. I'll set it like this:

<site name="MySiteName" id="42">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\my\desired\path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:63470:localhost" />
    </bindings>
</site>

However, when I reopen the project, Visual Studio overwrites my specified physical path, reverting it to the project's own directory. Even worse, Visual Studio gives me no indication that it has done this. Here's how the <virtualDirectory> element looks after Visual Studio messes it up:

        <virtualDirectory path="/" physicalPath="c:\path\to\project" />

How can I prevent Visual Studio from overwriting this path?

like image 339
Bryan Avatar asked Jan 30 '14 20:01

Bryan


People also ask

How do I change IIS Express settings in Visual Studio?

Configure IIS express on visual studioSelect the web application project and open properties -> select the web tab -> under server's select IIS express-> Specify the project URL. Now open the project folder and . vs folder (Hidden) -> Config -> applicationhost.

What is IIS applicationHost config?

ApplicationHost. config is the root file of the configuration system when you are using IIS 7 and above. It includes definitions of all sites, applications, virtual directories and application pools, as well as global defaults for the web server settings (similar to machine.

Does IIS Express use web config?

Yes, IIS Express uses the same applicationhost. config and web. config files supported by IIS.

How do I configure Visual Studio for IIS Express?

How Do I Configure Visual Studio For Iis Express? Express on Visual Studio by selecting the web application project and opening properties. Next select the web tab -> choose server -> select IIS express. The project folder can now be accessed. Compare folder (Hidden) -> Configuration -> Applicationhost.

Is it possible to publish to IIS using Visual Studio?

You can, however, still publish to IIS using the Publish tool in Visual Studio. Web Deploy 3.6 for Hosting Servers provides additional configuration features that enable the creation of the publish settings file from the UI.

What is the IIS Express for VSCode extension?

IIS Express for VSCode. This extension gives you the power to run a folder open in Visual Studio Code as a website using an IIS Express web server.

How to configure IIS Express to use global application hosts?

Open your *.proj file and set the following entry: With this configuration, the IIS Express uses your global application host file located at: %userprofile%\documents\iisexpress\config\applicationhost.config.


2 Answers

Visual Studio 2013 and 2015 does not change the physical path for the option 'Override applicationpool URL':

enter image description here

The file %userprofile%\documents\iisexpress\config\applicationhost.config looks like the following as default:

<site name="MyWebSite" id="1477659296">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Projects\MyWebSite" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:62238:localhost" />
        <binding protocol="http" bindingInformation="*:62238:*" />
    </bindings>
</site>

Just copy the your default block above, paste it directly below and make some changes. Change the name, id, physicalPath and override the URL with the additional subdomain. In my case debug:

<site name="MyWebSiteOverwritten" id="99999999">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Projects\DifferentPath" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:62238:debug.localhost" />
    </bindings>
</site>

Now, when I start VS and run the IIS Express, Visual studio does not change the physicalPath in the applicationhost.config of the overwritten URL. That works for me.

Hint for Visual Studio 2015: Visual Studio 2015 uses the file YourProject/.vs/config/applicationhost.config and overrides it every time you open the environment. Open your *.proj file and set the following entry:

<UseGlobalApplicationHostFile>true</UseGlobalApplicationHostFile>

With this configuration, the IIS Express uses your global application host file located at: %userprofile%\documents\iisexpress\config\applicationhost.config.

like image 109
Simon Avatar answered Oct 17 '22 15:10

Simon


I wasn't able to prevent VS to override the physicalPath for MySiteName but as a workaround I added another application section with different path (lets say "NewPath") and didn't update VS to use this path under the csproj web properties. In this case when debugging it will automatically open the browser on the old url (http://localhost:63470/) if you navigate to the new endpoint (http://localhost:63470/NewPath) everything will work fine and VS will not revert this.

So the new configuration looks like this:

<site name="MySiteName" id="42">
     <application path="/" applicationPool="Clr4IntegratedAppPool">
         <virtualDirectory path="/" physicalPath="c:\path\to\project" />
     </application>
     <application path="/NewPath" applicationPool="Clr4IntegratedAppPool">
         <virtualDirectory path="/" physicalPath="c:\my\desired\path" />
     </application>
     <bindings>
         <binding protocol="http" bindingInformation="*:63470:localhost" />
     </bindings>
</site>
like image 33
oribarak Avatar answered Oct 17 '22 15:10

oribarak