2017-10-19 75 views
0

我正在使用網絡掃描解決方案,並試圖將文件從aspx頁面重定向到mvc控制器。掃描的圖像使它成爲aspx頁面,但我無法弄清楚如何將文件傳送到MVC控制器。 這裏是我的代碼:從ASPX頁面發送文件到mvc控制器

  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; 

我嘗試使用的Response.Redirect在URL中的文件,但它一直越來越下降。該文件被掃描並且在客戶端計算機上沒有保存的路徑(潛在的醫療記錄+ HIPAA使得該路徑成爲禁止)。我錯過了什麼?


我試着重做路線,現在scanner.aspx接管所有路由。這裏的路由方法:

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

這裏的周圍多一點戳後的最新更新。

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

控制器名稱是TextDocumentsController,動作GetScannedDocument


這件事正在成爲一本書......我參加了一個更好看一些附加的例子,我得到了的MapPageRoute到工作。但我仍然看着我的scanner.aspx.cs頁面,我不確定如何將HttpPostedFile傳遞給我的MVC控制器。


這是我的MapPageRoute,因爲它現在坐。它仍然會將我發送給aspx頁面上的代碼,而不是MVC控制器。我錯過了什麼?

 routes.MapPageRoute("Scanner", 
      "TextDocuments/GetScannedDocument", 
      "~/UtilityClasses/scanner.aspx", 
      true, null, 
      new RouteValueDictionary { { "incoming", new MyCustomConstaint()} }); 
+0

是否在相同或不同的網站控制器和aspx頁面? –

+0

同一個網站。如果可以的話,我會避開ASPX頁面,但我們使用的掃描解決方案需要它。 – Mykal73

+2

爲什麼不直接將ASPX的路徑映射到操作?它仍然看起來像掃描解決方案的ASPX頁面,但實際上將流量路由到您的控制器。 –

回答

-1

使用

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