In Startup.cs file, add the code:
// 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"),//指定实际物理路径
});
}
The role of background above code is run on the IIS server project
If you need to debug locally, you can change the code:
// 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
});
}