Okay, I just want to add an updated answer to this question, as it is the first one coming up on google, and I was having a hard time getting the current answer to work.
there are 3 things you need to change in the applicationhost.config to make it work.
the config generated in VS2022 generates an AppPool with the name of the Project (in my example "IISVirtualFolderFix AppPool")
step 1) change the path of the application
in the section of the config, there should be a generated with the name attribute named the same as your project (in my example "IISVirtualFolderFix").
there should already be an application using the current application pool
<site name="IISVirtualFolderFix" id="2">
<application path="/" applicationPool="IISVirtualFolderFix AppPool">
<virtualDirectory path="/" physicalPath="E:\Codes\Experiments\AspNetCore\IISVirtualFolderFix\IISVirtualFolderFix" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54180:localhost" />
<binding protocol="https" bindingInformation="*:44381:localhost" />
</bindings>
</site>
you can change the above code to
<site name="IISVirtualFolderFix" id="2">
<application path="/" applicationPool="IISVirtualFolderFix AppPool">
<virtualDirectory path="/sub" physicalPath="E:\Codes\Experiments\AspNetCore\IISVirtualFolderFix\IISVirtualFolderFix" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54180:localhost" />
<binding protocol="https" bindingInformation="*:44381:localhost" />
</bindings>
</site>
now the problem is, that you still need to do more before it works.
step 2) add root application
the site needs a root application before it can navigate down to the children.
this is very easy... simply change the to look like this.
<site name="IISVirtualFolderFix" id="2">
<application path="/"></application>
<application path="/sub" applicationPool="IISVirtualFolderFix AppPool">
<virtualDirectory path="/" physicalPath="E:\Codes\Experiments\AspNetCore\IISVirtualFolderFix\IISVirtualFolderFix" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:54180:localhost" />
<binding protocol="https" bindingInformation="*:44381:localhost" />
</bindings>
</site>
step 3) allow processing of aspnetcore in sub-applications
as default, the processing of the asp.net core is only permitted in the root-dir, meaning you have to allow inheritance of this setting to all sub-applications.
there should be a location section with a path to the project folder (in my example "IISVirtualFolderFix" with an attribute named inheritInChildApplications set to false, change that to true.
<location path="IISVirtualFolderFix" inheritInChildApplications="true">
<system.webServer>
<modules>
<remove name="WebMatrixSupportModule" />
</modules>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" stdoutLogEnabled="false" hostingModel="InProcess" startupTimeLimit="3600" requestTimeout="23:00:00" />
<httpCompression>
<dynamicTypes>
<add mimeType="text/event-stream" enabled="false" />
</dynamicTypes>
</httpCompression>
</system.webServer>
</location>
All done.
now your sub-application should work.
however, you will still start debugging in the root dir, and that can also be fixed.
in the Properties/launchSettings.json
find the profiles/IIS Express object, and add the launchUrl field.
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54180",
"sslPort": 44381
}
},
"profiles": {
"IISVirtualFolderFix": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7247;http://localhost:5247",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchUrl": "sub",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}