Asp net core app only works as root


ASP.NET is a popular programming language used for building web . However, one common issue that developers face is that ASP.NET Core apps only work as root. In this article, we will explore this and provide solutions with .

The Problem

By default, ASP.NET Core apps are configured to work only as root. This means that the application can only be accessed using the root URL, such as “”. If you try to access the application using a subdirectory, such as “”, it will result in a 404 error.

Solution 1: Use PathBase

To solve this issue, you can use the PathBase middleware in your ASP.NET Core app. This middleware allows you to a base path for your application, so it can be accessed using a subdirectory.

public void (IApplicationBuilder app, IWebHostEnvironment env)
    // Other middleware configurations
    // ...

By adding the UsePathBase middleware and specifying the desired subdirectory (“/myapp” in this example), your ASP.NET Core app will be accessible using the URL “”.

Solution 2: Use Reverse Proxy

Another solution is to use a reverse proxy server, such as Nginx or Apache, to from a subdirectory to the root URL of your ASP.NET Core app.

First, configure your reverse proxy server to redirect requests from the subdirectory to the root URL. For example, in Nginx, you can add the following configuration:

location /myapp {
    proxy_pass http://localhost:5000;

This configuration tells Nginx to redirect requests from “/myapp” to the root URL of your ASP.NET Core app running on localhost:5000.

Next, make sure your ASP.NET Core app is to work as root. Remove any base path configurations or middleware that specify a subdirectory.


ASP.NET Core apps only working as root can be a limitation, but it can be overcome by using the PathBase middleware or a reverse proxy server. By following the solutions provided in this article, you can make your ASP.NET Core app using a subdirectory.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents