This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2450|Reply: 0

[ASP.NET] ASP.NET Core (twenty-nine) is deployed in a subdirectory (virtual directory) of the site

[Copy link]
Posted on 5/12/2024 6:18:20 PM | | | |
Requirements: ASP.NET the Core project is accessed as a subdirectory of the site, after reverse proxying the path to the project via nginx, the accessing project will encounter the problem that the page does not render properly (CSS and JS files will report a 404 error due to path problemsHow do I deploy a project in a site subdirectory (virtual directory)?

ASP.NET Core has a UsePathBase extension method that uses a middleware to add or remove a root path (Pathbase) to the current http request, address:The hyperlink login is visible.

Edit the Program.cs file to add the UsePathBase extension method to the WebApplication with the following code:

This article takes the environment configuration as an example, you need to modify the launchSettings.json file in the Properties directory, as follows:

Start the project and access it through the subdirectory /folder1, and you can find that all the paths have been automatically added to the base path for us, as shown in the figure below:



If you start a project via systemd, the environment variables are configured as follows:

(End)





Previous:ASP.NET Core (twenty-eight) stores application secrets in development
Next:Failed to execute 'atob' on 'Window': The string to be decoded is not...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com