2017-10-19 34 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"); 
}