yavsc/Yavsc/Startup/Startup.FileServer.cs
2016-11-14 12:17:07 +01:00

34 lines
1.1 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles;
namespace Yavsc
{
public partial class Startup
{
public static string UserFilesDirName { get; private set; }
public static FileServerOptions UserFilesOptions { get; private set; }
public void ConfigureFileServerApp(IApplicationBuilder app,
SiteSettings siteSettings, IHostingEnvironment env)
{
var userFilesDirInfo = new DirectoryInfo( siteSettings.UserFiles.DirName );
UserFilesDirName = userFilesDirInfo.FullName;
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
UserFilesOptions = new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(UserFilesDirName),
RequestPath = new PathString("/" + siteSettings.UserFiles.DirName),
EnableDirectoryBrowsing = env.IsDevelopment()
};
app.UseFileServer(UserFilesOptions);
app.UseStaticFiles();
}
}
}