0

I would like to map the URL http://localhost:49930/upload -

RouteConfig.cs-

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
             namespaces: new[] { "BrSupervisorTracker.Controllers" }
        );

        routes.MapRoute(
            name: "ExcelUploader",
            url: "upload/{controller}/{action}/{id}",             
            defaults: new { controller = "FileUpload", action = "Index", id = UrlParameter.Optional },
             namespaces: new[] { "BrSupervisorTracker.Controllers" } 
        );
    }
}

Controller-

public class FileUploadController : Controller
{
    public ActionResult Index()
    {
        return View("ExcelUpload");
    }
}

But it's not working. Returns HTTP 404. Any help?

2
  • 2
    Order matters- specific routes need to come first. Move the ExcelUploader route before the default and change the url to url: "upload", (remove the /{controller}/{action}/{id}) Commented Dec 11, 2016 at 9:58
  • @StephenMuecke, Thanks. It's working after re-order. Make it an answer. Commented Dec 11, 2016 at 9:59

1 Answer 1

1

Routes get evaluated in order so ../upload matches your first (Default) route and attempts to call the Index() method of UploadController which does not exist, hence the 404 response.

Swap the routes so the ExcelUploader routes is before the Default route, and also remove the unnecessary segments/parameters

routes.MapRoute(
    name: "ExcelUploader",
    url: "upload",
    defaults: new { controller = "FileUpload", action = "Index"},
    namespaces: new[] { "BrSupervisorTracker.Controllers" } 
);
routes.MapRoute(
    name: "Default",
    ....
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.