问题
I've found this answer coherent to this old article but both don't work. Thus I'm here to ask a new solution that works with VS2017. I'll explain more in detail: First time you define a virtual directory (as "/site1" and physical folder "site\site1") and try to publish from VS2017, you receive an error (cannot write into the specified path) and cannot publish. Then if you enter into the console (from portal.azure.com) and manually create the folder under d:\site with "md site1"), the publish process works (and lot of files have been created under the new folder) and finishes with a "1 successful...", BUT when you browse to the new ..../site1 you receive the following error message: "The page cannot be displayed because an internal server error has occurred."
Cannot find anything around on the web to solve this specific error (in one old doc they were saying it is due to separate git repos for the 2 projects (in the same solution), one targeting to the root folder and another one targeting the virtual directory, but I cannot understand why different source controls should make troubles in production when publishing through VS2017)...
Anybody know how to solve this?
UPDATE as requested by David Ebbo: I think the problem is a configuration problem Azure side (the other articles don't explain you have to create a physical folder through console when defining virtual directories) and/or runtime error (when the physical folder is created the publishing process from VS2017 works and it is completed successfully).
Here are more details to understand the context: 1) the Visual Studio Solution contains 2 project: one "main project" (empty .NET Core project with "Hello world!") with publish profile targeting the root folder of the Azure website + another "child project" (standard MVC Core.NET template project with no customization) with publish profile targeting the same Azure site with "/site1" added to the tail of "site name" and "site url". 2) If I try to publish the child project to the root folder of the site, everything works fine (but of course I overwrite the "main project"), thus it's not a code/version problem. 3) Going through console, I can see the folder d:\home\site\site1 contains files "similar" to the ones present in d:\home\site\wwwroot for the main project.
回答1:
First time you define a virtual directory (as "/site1" and physical folder "site\site1") and try to publish from VS2017, you receive an error (cannot write into the specified path) and cannot publish.
I create a virtual directory and publish a web application from VS 2017. I can't reproduced your issue. Here are my detail steps.
Step 1. Create a virtual directory from Azure portal. Please make sure you have checked the [Application] checkbox and clicked the [Save] button.
Step 2. Deploy a web application using VS 2017. Search and choose an App Service from VS deploy window.
Step 3. Click settings button to configure the virtual directory.
Step 4. Change the site name and destination URL based on the virtual directory name.
Step 5. Click publish button to publish the web application.
After publish my web application, I can view the web application successfully from following URL.
http://mysitename.azurewebsites.net/site1
Please check whether there are any differences between my steps and yours.
when you browse to the new ..../site1 you receive the following error message: "The page cannot be displayed because an internal server error has occurred."
If it caused by your web application, I suggest you change customErrors mode property as 'Off' to view detail error message.
<system.web>
<customErrors mode="Off" />
</system.web>
Edit 2017/6/13 10:37
The issue is related to ASP.NET Core. When I publishing a ASP.NET Core web application, I can reproduce the issue.
We can find the reason from this official document.
When adding applications to an IIS Site's root application, the root application web.config file should include the section, which adds the ASP.NET Core Module as a handler for the app. Applications added to the root application shouldn't include the section. If you repeat the section in a sub-application's web.config file, you will receive a 500.19 (Internal Server Error) referencing the faulty config file when you attempt to browse the sub-application.
To solve this, we need to edit the web.config file in this sub directory. We can do it using kudu console. Click the edit button in front of web.config file.
Remove the aspNetCore handler and click save.
来源:https://stackoverflow.com/questions/44489249/using-virtual-directories-in-a-single-azure-website