Razor pages on Azure

Hi @mythz,

I am currently trying to deploy a netcore 2.1 app to Azure with ServiceStack Razor pages.v5.1.1

Everything works locally but when I publish to Azure, the default page loads ok but when I hit a page requiring a service dto response, I’m getting the metadata html view back instead of the view I expect.

My config is basically the same as https://github.com/NetCoreApps/RazorRockstars/blob/master/src/RazorRockstars.WebHost/Startup.cs

Is there anything you might know of that is causing the compiled views to not be found and return the native html response instead?

[EDIT] Actually happening locally too using dotnet .\myapp.dll in the folder generated after running dotnet publish

ServiceStack Razor in .NET Core uses MVC’s APIs to access and render views so it’s essentially all handled by MVC libraries and build tools.

You should instead use https://github.com/NetCoreTemplates/razor for a reference impl.

I don’t see why this would affect Azure as they should be running the published .NET Core App, can you publish the App and run the published release build, e.g.

$ dotnet publish -c Release

Then run it with:

$ cd bin\Release\netcoreapp2.1\publish
$ dotnet MyApp.dll

Use whatever your Host project name is. I’ve just done this for a new Razor project and it’s running as expected. This has also been deployed to:

http://razor.web-templates.io

Found the culprit.

I was using an array response type

    [Authenticate, RequiredRole(Roles.Member)]
    [DefaultView("products")]
    public class ProductService : Service
    {
        public object Any(ProductsRequest request)
        {
            return new ProductsResponse
            {
                Products = new [] { new Product { .. } }
            };
        }
    }
    
    [Route("/products")]
    public class ProductsRequest : IGet, IReturn<ProductsResponse>
    {
    }

    public class ProductsResponse
    {
        // was just returning Product[] with a view products.cshtml with same model type - Product[] specified
        // changed to use ProductsResponse type (and updated view vm) and it worked.
        // if I remove DefaultView attribute from service again it doesn't find view which I thought by convention it would
        public Product[] Products { get; set; } 
    }
    
    public class Product
    {
        public int Id { get; set; }
    }

hmm spoke too soon. Whilst the views now resolve running from a publish directory, they are still not resolving when published to Azure.

Could this be something to do with a path (root/virtual)? Kinda stumped at the moment why it’s happening!

Sounds like a deployment issue, I’ve only known .NET Core App deployments to deploy the published .NET Core App.

When creating a release build of your App your compiled views are in MyApp.Views.dll so there shouldn’t be any path issues as they’re resolved from compiled classes inside a .NET .dll so they should not be impacted by any static files or path issues.

So finally got to the bottom of why the pages were not rendering. Solution below in case anyone else encounters this.

I had the views in Views/Pages. When I moved them to the Views folder, they were picked up correctly on Azure. No idea why as this worked fine locally when testing and publishing.

1 Like