I have a simple asp.net mvc 4 website with an admin area. I have defined a custom http handler to handle uploads from a plupload script that runs in the admin area. Here is the code for the handler :
public class CategoryImageUploadHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files[0];
var categoryID = context.Request["categoryID"];
var fileName = Path.GetFileName(file.FileName);
var parentPath = HttpContext.Current.Server.MapPath("~/Files/Content");
var targetDir = Path.Combine(parentPath, categoryID);
var targetFile = Path.Combine(targetDir, fileName);
//check if Directory exists
if (Directory.Exists(targetDir))
file.SaveAs(targetFile);
else
{
Directory.CreateDirectory(targetDir);
file.SaveAs(targetFile);
}
context.Response.Write("/"+categoryID+"/"+fileName);
}
catch (Exception ex)
{
context.Response.Write("0");
context.Response.Write(ex.Message);
}
}
public bool IsReusable
{
get { return false; }
}
}
This is sitting in the Handlers/ directory of the main site. This is how I have registered the handler :
<system.webserver>
<add name="CategoryImageUploadHandler path="Admin/CategoryImageUploadHandler.ashx" verb="*" type="Hitaishi.Web.Handlers.CategoryImageUploadHandler, Hitaishi.Web"/>
<system.web>
<httpHandlers>
<add path="Admin/CategoryImageUploadHandler.ashx" verb="*" type="Hitaishi.Web.Handlers.CategoryImageUploadHandler, Hitaishi.Web"/>
Routeconfig.cs:
routes.IgnoreRoute("{*allashx}", new { allashx = @".*\.ashx(/.*)?" });
However, when the plupload sends a POST to the http handler from the Admin area, the call is still picked up by routing as it tries to look for
/Admin/CategoryImageUploadHandler.ashx
I have tried playing with slashes to check if the path I am giving is wrong or changing path in the registrations, but nothing seems to work. I am still getting 404 errors.
In a nutshell, I need a way to reference a HttpHandler defined in the main MVC area of the website from another mvc area of the website. Can anyone help with this?