yavsc/Yavsc/Startup/Startup.FileServer.cs

49 lines
1.7 KiB
C#

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; }
8 years ago
8 years ago
public static FileServerOptions AvatarsOptions { get; set; }
public void ConfigureFileServerApp(IApplicationBuilder app,
SiteSettings siteSettings, IHostingEnvironment env)
{
8 years ago
var userFilesDirInfo = new DirectoryInfo( siteSettings.UserFiles.Blog );
8 years ago
UserFilesDirName = userFilesDirInfo.FullName;
8 years ago
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
UserFilesOptions = new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(UserFilesDirName),
8 years ago
RequestPath = new PathString(Constants.UserFilesPath),
EnableDirectoryBrowsing = env.IsDevelopment()
};
8 years ago
var avatarsDirInfo = new DirectoryInfo(Startup.SiteSetup.UserFiles.Avatars);
if (!avatarsDirInfo.Exists) avatarsDirInfo.Create();
AvatarsDirName = avatarsDirInfo.FullName;
AvatarsOptions = new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(AvatarsDirName),
RequestPath = new PathString(Constants.AvatarsPath),
EnableDirectoryBrowsing = env.IsDevelopment()
};
app.UseFileServer(UserFilesOptions);
8 years ago
app.UseFileServer(AvatarsOptions);
app.UseStaticFiles();
}
}
}