gpt4 book ai didi

c# - 将 Razor Web App 作为中间件插入 Web Api 元素时,不会加载 css

转载 作者:行者123 更新时间:2023-12-04 13:25:52 25 4
gpt4 key购买 nike

我想创建 razor 应用程序,它可以插入另一个 .net Web 应用程序。
我成功做到了,但是 razor 元素没有加载像 *.css 和 *.js 这样的静态文件,所以页面在纯 html 中看起来很难看。 wwwroot 和其他文件夹在浏览器中无法访问。
如何在 razor 应用程序中隔离 css 和 js 文件?
还有 github 链接到具有最小更改的默认元素。
链接不真实,请看答案
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
}

最佳答案

所以,经过几天的调查,我发现了这个问题。
Can Razor Class Library pack static files (js, css etc) too?
Ehsan Mirsaeedi 提供了一种将静态文件嵌入 RCL 的工作方法,它适用于我的元素。这是回答 https://stackoverflow.com/a/53024912 的链接.

关于c# - 将 Razor Web App 作为中间件插入 Web Api 元素时,不会加载 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68635168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com