0

I'm working with a web scanning solution and I'm trying to redirect a file from an aspx page to an mvc controller. The scanned image makes it to the aspx page fine, but I can't figure out how to get the file to the MVC controller. Here's my code:

            HttpFileCollection files = HttpContext.Current.Request.Files;
            HttpPostedFile uploadfile = files["RemoteFile"];string fileName = uploadfile.FileName;
            string seqNum = HttpContext.Current.Request.Form["sequenceNum"];
            string imageIndex = HttpContext.Current.Request.Form["imageIndex"];
            string docId = HttpContext.Current.Request.Form["docId"];
            string guid = HttpContext.Current.Request.Form["guid"];
            string url = "/controller/action/" + guid + "?fileName=" + fileName + "&imageIndex=" + imageIndex + "&sequenceNum=" + seqNum + "&docId=" + docId;

I tried using a Response.Redirect with the file in the url but it kept getting dropped. The file is scanned in and doesn't have a saved path on the client machine(potential medical records + HIPAA makes that a no-no). What am I missing?


I tried reworking the routes and now the scanner.aspx takes over all the routing. Here's the routing method:

public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapPageRoute("", "scanner.aspx", "~/UtilityClasses/scanner.aspx");
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{guid}",
            defaults: new { controller = "Login", action = "Index", guid = UrlParameter.Optional }
        );
    }

Here's the latest update after poking around a bit more.

public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapPageRoute("", "scanner.aspx", "~/TextDocuments/GetScannedDocument");
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{guid}",
            defaults: new { controller = "Login", action = "Index", guid = UrlParameter.Optional }
        );
    }

The controller name is TextDocumentsController and the action is GetScannedDocument


This thing is becoming a book... I took a better look at some of the attached examples and I got the MapPageRoute to work. But I'm still looking at my scanner.aspx.cs page and I'm not sure how to get the HttpPostedFile to my MVC controller.


Here's my MapPageRoute as it sits now. it's still sending me to the code behind on the aspx page and not the MVC controller. What am I missing?

        routes.MapPageRoute("Scanner",
            "TextDocuments/GetScannedDocument",
            "~/UtilityClasses/scanner.aspx", 
            true, null, 
            new RouteValueDictionary { { "incoming", new MyCustomConstaint()} });
Mykal73
  • 478
  • 4
  • 6
  • 18
  • Are the controller and aspx page in the same or different web sites? – John Wu Oct 19 '17 at 21:09
  • Same web site. I would avoid the ASPX page if I could, but the scanning solution we're using requires it. – Mykal73 Oct 19 '17 at 21:12
  • 2
    Why not map the path of the ASPX directly to the action? It'll still look like an ASPX page to the scanning solution, but would actually route the traffic to your controller. – John Wu Oct 19 '17 at 21:15
  • when I do the MapPageRoute it takes over and all I can do is log in. – Mykal73 Oct 19 '17 at 21:41
  • `routes.MapPageRoute("", "scanner.aspx", "~/TextDocuments/GetScannedDocument");` You have the second and third parameters the wrong way around. Check out https://stackoverflow.com/a/10178849/34092 . You probably want `routes.MapPageRoute("", "TextDocuments/GetScannedDocument", "~/whateverthepathis/scanner.aspx");` – mjwills Oct 19 '17 at 22:15
  • Ok, I'll try it when I get back to my computer – Mykal73 Oct 19 '17 at 22:47
  • Did that work @Mykal73 ? – mjwills Oct 20 '17 at 03:01
  • I managed to get the routing to work, but I'm still left with the issue that I have a file in the code behind I can't get to the controller. – Mykal73 Oct 20 '17 at 18:42

1 Answers1

-1

use Server.MapPath

public ViewResult ShowForm()
{
    //Logo
    ViewBag.Img = Server.MapPath("~") + @"Content\Images\Logo.png";
    return View("ShowForm");
}