I am developing multiple asp.net core applications within one solution and when I run the solution in Visual Studio using IIS Express, would like to have them under the same
I'm gradually moving a large ASPX app from .Net Framework 4.8 to .Net 5. I ran into a similar problem today. Running two .Net Framework apps together via IIS Express 'just works', but it doesn't necessarily work as easily for .Net Core / 5. I wished to host the legacy portion of the site in the existing web project and root of the website, and I wish to host the .Net 5 portion of the site in a virtual directory under the root. My two sites needed to work together because of claims based auth shared between the two apps, but I was having a heck of a time getting Visual Studio IIS Express integration to work properly and consistently between the two projects. For me, the recipe to getting it working was as follows:
Update both configs for the apps to run on the same host and port but in different directories. One directory may be a parent of the other, or they may be parallel. Both apps must be in the same solution (which is the whole reason we care here, right?). This may entail altering the launchSettings.json and/or the .csproj file, depending on what version of .Net you're using since ports are otherwise assigned randomly by Visual Studio when creating a project, and there isn't a way to change it via the UI. To make sure the hosts and ports are correct after changing them, you can inspect the settings by viewing the project 'Properties' element in Solution Explorer, in the Web or Debug tabs, depending on .Net version.
Make sure there is a web.config file in the root of any .Net 5 / Core web app that is part of the solution. This is key in making sure settings won't get nutty in the applicationHost.config, and this was the part I was missing. The default Visual Studio behavior and default .Net 5 web app templates will result in something like this in the applicationHost.config, and this is the problem when running multiple apps together:
Problematic resulting applicationHost.config snippet:
The problem here is %LAUNCHER_PATH% isn't consistent, depending on which app you start. To keep config like that from being added to the applicationHost.config, you can add a web.config to the root of each .Net Core/5 app similar to this:
Your config may vary. The key here is just to replace %LAUNCHER_PATH% with a path to the exe in the local web.config that IIS Express will pick up no matter how the apps are launched or how the apps are related to one another. You may need to use OutOfProcess hostingModel, and/or you may need to specify some other parameters like the HTTPS port. You may need to adjust the applicationHost.config to clean up any prior mess that may have been left in it. Deleting and letting VS recreate the applicationHost.config may even help.
If you continue to get errors, try stopping IIS Express via your system tray and restart it. In spite of being able to use all the apps at the same time in IIS Express, you still cannot 'View in Browser' for one of the apps while IIS Express is busy serving the solution from the standpoint of the one of the other apps. This also has the unfortunate side effect of locking the output .exe while apps are being served, so killing IIS Express may need to be a regular occurrence to fix build errors. Depending on your particular situation, you may also need to change some other applicationHost.config settings to allow overriding settings in local web.config files. e.g. overrideModeDefault="Allow" and/or lockItem="false".