我试图获取本地图像文件的路径,但无法弄清相对路径的位置。通常,我会将它们从wwwroot / images文件夹中删除,但是当我尝试从那里加载它们时会失败。
您在Angular 2中从哪里获得相对路径?我使用generator-aspnetcore-spa创建了应用程序。
https://github.com/aspnet/JavaScriptServices
http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/
例如在ClientApp / components / app / app.ts文件夹中。
我将图像文件夹放在哪里,如何命名它的路径?
在里面 Program.cs
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
将UseContentRoot
默认为您的应用程序的当前目录。
通过调用app.UseStaticFiles();
Startup类
public class Startup
{
...
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseStaticFiles();
静态文件中间件已启用。使用默认设置,它将为Web根文件夹(<content root>/wwwroot
)中的所有文件提供服务。
如果查看https://github.com/aspnet/JavaScriptServices Angular2模板,您将在webpack.config.js中看到输出存储在
output: {
path: path.join(__dirname, 'wwwroot', 'dist'),
filename: '[name].js',
publicPath: '/dist/'
},
因此,<content root>/wwwroot/dist
URL将是
http://<whatever host and port>/dist/<my file>
该URL不必包含ClientApp
(内容根级别,不能由静态文件中间件访问),而必须包含dist
(wwwroot级别)。
因此,将您的images
文件夹放入...\wwwroot\images
,图片URL将为http://<whatever host and port>/images/<my image file>
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句