After successfully creating a Razor app that can be plugged into another .NET web application, I encountered an issue where the static files like *.css and *.js were not loading in the Razor project. This led to the page looking plain with just HTML. The wwwroot and other folders seemed unreachable in the browser. How can I isolate the CSS and JS files within the Razor app?
If you are looking for default projects with minimal changes, please refer to this GitHub link.
//Code snippet from the pluggable razor app
//Extension methods to add the Razor app
public static IServiceCollection AddRoseQuartz(this IServiceCollection services)
{
services.AddRazorPages();
return services;
}
//Method to include routing and static files
public static IApplicationBuilder UseRoseQuartz(this IApplicationBuilder builder)
{
builder.UseStaticFiles();
builder.UseRouting();
builder.UseEndpoints(endpoints => { endpoints.MapRazorPages(); });
return builder;
}
//Code snippet from the main project
// ConfigureServices method which adds services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddRoseQuartz();
services.AddControllers();
}
// Configure method which configures the HTTP request pipeline
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRoseQuartz();
//Additional startup code here
}