How to publish my first Razor pages app

Glenn 21 Reputation points

Hi guys,
I installed Visual Studio a few weeks back and started a Razor pages project. I've done the absolute minimum of changes, I've really only played with the _layout, some javascript, and the views.

Yesterday i tried to publish my app both to azure and to hostgator(plesk) windows server and neither work. I basically used the publishing wizard in Visual Studio and just next,next,next'd it home.

I must have made some dire mistakes along the way. I'm using .net 5 and cant find any logs on the azure portal to give me a hint at whats wrong. Can I ask you guys to spend some of your valuable time to help me out? I had a great time making the website/webapp but feeling pretty bummed out that I cant get it published.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,308 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,056 Reputation points Microsoft Vendor

    Hi @Glenn ,

    System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/site/wwwroot/~assets/gallery

    By default, in core application, the Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot, but it can be changed with the UseWebRoot method.

    Please check your Startup.cs file, whether you have changed the default web root directory.

    The default setting like this: use the app.UseStaticFiles();:

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)  
            if (env.IsDevelopment())  
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see  
            app.UseEndpoints(endpoints =>  

    If you are using the default root directory, I suggest you could try to put the assets/gallery folder in the wwwroot, like this:


    Then, in the OnGet method, you can get the file path via the IWebHostEnvironment, code as below:

    public class ImageIndexModel : PageModel  
        public string[] imgPaths { get; set; }  
        //required using Microsoft.AspNetCore.Hosting;  
        private IWebHostEnvironment _environment;  
        public ImageIndexModel (IWebHostEnvironment environment)  
            _environment = environment;  
        public void OnGet()  
            var filefolder = Path.Combine(_environment.WebRootPath, "assets", "gallery");  
            imgPaths = Directory.GetFiles(filefolder).Select(file => Path.GetFileName(file)).ToArray();  

    The result as below:


    After that, you can republish the application to the Azure web application (after publishing, you can also use Kudu to check if the gallery folder contains image file) and check if the website works.

    More detail information about the Static files, see Static files in ASP.NET Core.

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful