更新时间:2023-02-14 16:19:44
您应将希望公开的静态文件放在 wwwroot
下,然后相应地引用它们,例如
You should place the static files you wish to expose under wwwroot
and then reference them accordingly e.g.
<link rel="stylesheet" href="~/css/style.css" asp-append-version="true" />
如果要在 wwwroot
之外提供静态文件,则需要按以下方式配置静态文件中间件:
If you want to serve static files outside of the wwwroot
then you will need to configure static file middleware as follows:
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(); // For the wwwroot folder
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Content")),
RequestPath = "/Content"
});
}
然后,您可以使用与当前相似的标记:
You can then use similar markup to what you have currently:
<link href="@Url.Content("~/Content/css/style.css")" rel="stylesheet">
See Serve files outside of web root for more information.