public FileHandler()
{
}
bool IHttpHandler.IsReusable
{
get { return false; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
{
// Is the user logged-in?
if (!context.User.Identity.IsAuthenticated)
{
System.Web.HttpContext.Current.Response.Redirect("/");
return;
}
string requestedFile = context.Server.MapPath(context.Request.FilePath);
SendContentTypeAndFile(context, requestedFile);
break;
}
}
}
HttpContext SendContentTypeAndFile(HttpContext context, String strFile)
{
context.Response.ContentType = GetContentType(strFile);
context.Response.TransmitFile(strFile);
context.Response.End();
return context;
}
public string GetContentType(string filename)
{
// used to set the encoding for the reponse stream
string res = null;
FileInfo fileinfo = new FileInfo(filename);
if (fileinfo.Exists)
{
switch (fileinfo.Extension.Remove(0, 1).ToLower())
{
case "pdf":
{
res = "application/pdf";
break;
}
case "doc":
{
res = "application/msword";
break;
}
case "docx":
{
res = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
break;
}
case "xls":
{
res = "application/vnd.ms-excel";
break;
}
case "xlsx":
{
res = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
break;
}
case "mp3":
{
res = "audio/mpeg";
break;
}
}
return res;
}
return null;
}
}
For those who may be experiencing the same issue I found a web.config in the media folder. I added my handler config into this web.config and now my handler fires OK.
ProcessRequest fails to fire
Hi
Since upgrading to Umbraco 7.5.2 from 7.2.8 the file handlers I had in place have stopped firing.
I can see nothing wrong in the code or config files.
Can anyone shed any light on what the issue may be?
Config file:
FileHandler.cs in App_Code directory
{ public class FileHandler : IHttpHandler {
}
For those who may be experiencing the same issue I found a web.config in the media folder. I added my handler config into this web.config and now my handler fires OK.
I have posted an article on resolving this issue and writing the handler itself. See here for more: https://www.steadygo.digital/blog/securing-media-files-umbraco-7-5-2/
is working on a reply...