2013-09-04 1 views
2

나는이 문제에 대한 해결책을 찾고자하지 않았다. 이 가이드를 사용하여 MVC2 응용 프로그램을 MVC3으로 업그레이드했습니다. http://www.asp.net/whitepapers/mvc3-release-notes#upgradingMVC3으로 업그레이드하십시오. ashx 리소스를 찾을 수 없습니다. 라우팅 문제가 있습니까?

또한 VS2008에서 VS2012로 프로젝트를 업그레이드했습니다. IIS 7.5

내 Preview.ashx가 리소스를 찾을 수 없다는 것을 제외하면 모든 것이 완벽하게 진행되었습니다. 이 페이지는 쿼리 문자열에 url과 함께 호출 될 때 미리보기 이미지를 표시합니다. 내가 변경 경로를 시도, 컨트롤러 이름을 확인, Web 설정 등 Specific Page 설정 나는 꽤 그게 루트 또는 업그레이 드 중에 망쳐있어 몇 가지 설정과 관련이 있다고 확신하지만, 그것을 알아낼 수 없습니다.

나는 http://localhost/comm

편집에서 IIS에서 가상 디렉터리를 사용하여 사이트의 설정을 가지고 : 난 그냥 MVC3의 새로운 설치를 사용하여 사이트를 재건하고 문제는 여전히 존재합니다. 사이트를 재건 한 후 잘 작동하는 동일한 디렉토리에 .aspx 파일이 있다는 것을 깨달았습니다. 올바르게 라우팅되지 않는 것은 .ashx 파일뿐입니다.

Global.asax에

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

    routes.MapRoute(
     "Default", // Route name 
     "{instance}/{controller}/{action}/{id}", // URL with parameters 
     new { instance = "demo", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
     ); 

    } 

    protected void Application_Start() { 
      AreaRegistration.RegisterAllAreas(); 
      RegisterRoutes(RouteTable.Routes); 
    } 

오류

The resource cannot be found. 

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /comm/Views/Review/FileViewer.ashx 
+1

프로젝트의 FileViewer.ashx의 실제 경로는 무엇입니까? – vpascoal

+0

C : /.../ MVCProjectRootFolder/Views/Review/FileViewer.ashx – coryrwest

+1

이 디렉터리에서 요청 된 모든 파일에서 404 응답을 만드는 Views 폴더에는 web.config가 있습니다. .ashx 파일을 다른 디렉토리로 이동하거나 올바른 MVC 방식으로 다시 만드는 것이 가장 좋습니다. – ZippyV

답변

0

내가 일하기 ashx를 얻기 위해 노력하고 포기하고 단지를 반환하는 컨트롤러의 FilesResult 조치를 구축 결국 영상. ashx은 이미지를 처리하여 반환하기 위해 HttpContext을 받았습니다. 나는 경로를 취하고 작업을 수행하며 이미지를 반환하는 작업을 만들었습니다. .ashx 파일과 MVC 라우팅에 대해 알아챌 수없는 뭔가가 있습니다. 내 ashx 파일 중 아무 것도 작동하지 않지만 모든 작업을 다시 빌드 할 수 있으므로 큰 문제는 아닙니다. 다음은 해당 작업을 대체하는 작업입니다. Preview.ashx

public FileResult Preview(string path) { 
// Database fetch of image details 
try { 
    // Get the relative path 
    if (!path.IsNull()) { 
     // Get the path 
     string filePath = path; 
     string absolutePath = ... 

     // Make sure the the file exists 
     if (System.IO.File.Exists(absolutePath)) { 
      // Check the preview 
      string previewPath = ...; 

      // Has preview 
      bool hasPreview = true; 
      // Check to see if the preview exists 
      if (!System.IO.File.Exists(previewPath) || System.IO.File.GetLastWriteTime(previewPath) < System.IO.File.GetLastWriteTime(absolutePath)) { 
       try { 
        // Generate preview 
        hasPreview = ... != null; 
       } 
       catch (Exception exc) { 
        hasPreview = false; 
       } 
      } 

      // Once the path is handled, set the type 
      if (hasPreview) { 
       return new FileStreamResult(new FileStream(previewPath, FileMode.Open), "image/png"); 
      } 
      // No preview 
      else 
       return WriteDefault(); 
     } 
     else 
      // Write the default (blank) 
      return WriteDefault(); 
    } 
    else { 
     return WriteDefault(); 
    } 
} 
catch { 
    // Write the default (no_photo) 
    return WriteDefault(); 
    } 
} 

private FileContentResult WriteDefault() { 
    // Write the default 
    System.Drawing.Bitmap bmp = new Bitmap(25, 25); 
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); 
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
    g.FillRectangle(System.Drawing.Brushes.White, 0, 0, 25, 25); 
    bmp = new Bitmap(25, 25, g); 
    MemoryStream str = new MemoryStream(); 
    bmp.Save(str, ImageFormat.Png); 
    return File(str.ToArray(), "image/png"); 
} 
관련 문제