在Startup.cs文件中,添加代码:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles(new StaticFileOptions()//自定义自己的文件路径,例如提供访问D盘下的Study目录,http://localhost:52723/MyStudy/README.md将访问D盘的Study目录中的README.md文件
{
RequestPath = new PathString("/UploadFiles")//对外的访问路径
FileProvider = new PhysicalFileProvider(@"C:\inetpub\wwwroot\UploadFiles"),//指定实际物理路径
});
}
上述代码的作用背景是项目在IIS服务器上运行
如果你还需要在本地调试,你可将代码修改为:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles(new StaticFileOptions()//自定义自己的文件路径,例如提供访问D盘下的Study目录,http://localhost:52723/MyStudy/README.md将访问D盘的Study目录中的README.md文件
{
#if DEBUG
RequestPath = new PathString("/UploadFiles")//对外的访问路径
#else
FileProvider = new PhysicalFileProvider(@"C:\inetpub\wwwroot\UploadFiles"),//指定实际物理路径
RequestPath = new PathString("/UploadFiles")//对外的访问路径
#endif
});
}