Search code examples
c#css.net.net-corerazor

Razor WebApp doesn't load css when plugged as middleware to WebApi project


I'd like to create razor app, which can be plugged into another .net web application. I successfully made it, but razor project doesn't load static files like *.css and *.js, so page looks ugly with pure html. The wwwroot and another folders are unreachable in browser. How can i isolate css and js files within razor app?

Also github link to default projects with minimal changes. link non actual, please look at answer https://github.com/ShockThunder/RoseQuartz

//Code from pluggable razor app
//Extension methods to add razor app
public static IServiceCollection AddRoseQuartz(this IServiceCollection services)
{
     services.AddRazorPages();
     return services;
}

//Another 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 from main project
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddRoseQuartz();
    services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseRoseQuartz();
    //another Startup code
} 

Solution

  • So, after some days of investigation, I found this question. Can Razor Class Library pack static files (js, css etc) too?

    Ehsan Mirsaeedi provided a working way to embed static files into RCL and it works for my project. Here is a link to answer https://stackoverflow.com/a/53024912.