Search code examples
c#razor-pageskestrel-http-server

Configure Kestrel Razor pages to be like PHP


I use PHP for simple web pages.

I use C# for a lot of non web programming, and have a lot of custom libraries.

I have been trying Razor pages with Kestrel using the ASP .Net core template in Visual studio, and I was expexting to have something like PHP but with C# code instead of PHP.

I would expect to be able to add and modify pages on the fly, and the C# code in my razor pages should be able to directly access any library or assembly loaded into the app that is hosting Kestrel.

What I am finding is that pages only update when the app is rebuilt, and that razor pages seem to rely on corresponding C# page model class, which I thought was a characteristic of the page/model view.

I realise that this may be just the specific configuration; but that is another issue, the configuration appears to be very complicated. I have project properties, json files, starup classes, what appear to be web server configuration factories that build interfaces to my servers configuration ( IHostBuilder CreateHostBuilder).....I can't really make head or tail of it, let alone establish what a minimal config for my needs would be.

So before I try and dig in further, is what I'm looking for actually possible, or should I be looking for some other lightweight built in webserver?


Solution

  • You can force immediate recompilation, just add this:

    services.AddRazorPages().AddRazorRuntimeCompilation();
    

    See more here: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation.