首先贴上微软的文档:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files
参考网址:http://www.cnblogs.com/wangrudong003/p/7592689.html#3877063
代码:
//虚拟目录实现apk文件下载 var path = filePath + @"apk"; app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(path), RequestPath = new PathString("/apk"), ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string> { { ".apk","application/vnd.android.package-archive"}, }) });
注:filePath为虚拟目录的物理地址
注意,原先的app.UseStaticFiles();不要删除,新增加一个即可,根据官方的说法这个是针对wwwroot( For the wwwroot folder)的,这让我对webapi配置的理解又深了一层,原来这些不一定都是唯一的,可重复配置。