-
-
Save anonymous/0f1442c986333f1899ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.Web; | |
public class DocumentFileHandler : StaticFileHandler | |
{ | |
public override IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback callback, object state) | |
{ | |
// Force Office-application to not open document directly from URL | |
var extension = Path.GetExtension(context.Request.Path); | |
if (OfficeExtensions.Contains(extension)) | |
context.Response.AppendHeader("content-disposition", "attachment"); | |
return base.BeginProcessRequest(context, callback, state); | |
} | |
protected override bool ProcessRequestInternal(HttpContext context) | |
{ | |
if (base.ProcessRequestInternal(context)) | |
{ | |
var extension = Path.GetExtension(context.Request.Path); // override missmatch in EPiServer | |
if (extension == ".pptx") | |
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; | |
var virtualFile = GenericHostingEnvironment.VirtualPathProvider.GetFile(context.Request.FilePath); | |
// TODO: Do something with the file...we add stats for number of downloads and handle some security stuff in here.... | |
} | |
return false; | |
} | |
private static IEnumerable<string> OfficeExtensions | |
{ | |
get | |
{ | |
return new[] { ".doc", ".ppt", ".xls", ".docx", ".pptx", ".xlsx" }; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment