当作为中间件插入 WebApi 项目时,Razor WebApp 不加载 css
Razor WebApp doesn't load css when plugged as middleware to WebApi project
我想创建 razor 应用程序,它可以插入另一个 .net web 应用程序。
我成功了,但是 razor 项目不加载像 *.css 和 *.js 这样的静态文件,所以纯 html 的页面看起来很难看。在浏览器中无法访问 wwwroot 和其他文件夹。
我如何在 Razor 应用程序中隔离 css 和 js 文件?
还有 github link 到默认项目,更改很少。
link非实际,请看答案
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
}
所以,经过几天的调查,我发现了这个问题。
Ehsan Mirsaeedi 提供了一种将静态文件嵌入 RCL 的工作方式,它适用于我的项目。这里有一个link来回答。
我想创建 razor 应用程序,它可以插入另一个 .net web 应用程序。 我成功了,但是 razor 项目不加载像 *.css 和 *.js 这样的静态文件,所以纯 html 的页面看起来很难看。在浏览器中无法访问 wwwroot 和其他文件夹。 我如何在 Razor 应用程序中隔离 css 和 js 文件?
还有 github link 到默认项目,更改很少。 link非实际,请看答案 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
}
所以,经过几天的调查,我发现了这个问题。
Ehsan Mirsaeedi 提供了一种将静态文件嵌入 RCL 的工作方式,它适用于我的项目。这里有一个link来回答