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()} });