在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 默认为您应用的当前目录。
通过在 Startup 类中调用 app.UseStaticFiles();
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/JavaScriptServicesAngular2 模板,你会在webpack.config.js 中看到输出存储在
output: {
path: path.join(__dirname, 'wwwroot', 'dist'),
filename: '[name].js',
publicPath: '/dist/'
},
那就是<content root>/wwwroot/dist,网址是
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>。