Wednesday, January 29, 2020

Renaming the wwwroot folder - .NET Core

In .NET Core, only the files with in the web root are served unlike in .NET. All the other files are blocked. So, you have to have all JavaScript, CSS and image files within the web root which by default is the wwwroot folder. Lets say you renamed the "wwwroot" folder to "Content", then you have to set the new name as the web root. Set it inside the main method of the Program.cs file.

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseWebRoot("Content")
            .UseIISIntegration()
            .UseStartup<MyStartup>()
            .Build();

        host.Run();
    }
}

No comments:

Post a Comment