I am trying to make a 404 handler for media, so far I have come up with this:
public class Media404Handler : INotFoundHandler
{
private int redirectId;
public bool Execute(string url)
{
var urlParts = url.Split('/');
if (urlParts.Contains("media"))
{
var qs = HttpContext.Current.Request.QueryString.ToString();
HttpContext.Current.Response.Redirect("/Assets/img/404.png" + (string.IsNullOrWhiteSpace(qs) ? "?" + qs : ""));
return true;
}
return false;
}
public bool CacheUrl
{
get { return false; }
}
public int redirectID
{
get { return redirectId; }
}
}
When I try to browse to /media/test404 it gets run like it should and redirects to /Assets/img/404.png, but if I browse to /media/test404.jpg nothing happens.
Is it just not possible to do this, or do I need to change the configuration somewhere?
404 handler for media
Hi
I am trying to make a 404 handler for media, so far I have come up with this:
When I try to browse to /media/test404 it gets run like it should and redirects to /Assets/img/404.png, but if I browse to /media/test404.jpg nothing happens.
Is it just not possible to do this, or do I need to change the configuration somewhere?
Got it working with an IIS rewrite - doesn't send a 404 status code, though. But thats ok in my case.
I'll add my tuppence to this, as I got this working with IIS error handling by configuring "/media/web.config" with:
Where "/404/" is my Umbraco not found page.
Ooh, nice - going to have a look into that!
Thanks for sharing!
is working on a reply...