2010-08-03 4 views
1

내 응용 프로그램에서 Mobile이라는 영역 호출이 있습니다. 이 영역에서 우리는 우리의 모든 CSS, 자바 스크립트 및 이미지를 배치하는 자산 폴더 호출이 있습니다.ASP.NET MVC 2에서 영역이있는 상대 경로를 사용할 수 없습니다.

보기에 액세스하면 정상적으로 작동합니다. http://localhost/webapp/mobile/stuff

문제는 내 CSS, 자바 스크립트 및 이미지에 액세스 할 때입니다.

내보기에는 이와 같은 작업을 수행 할 수 없습니다. 정적 파일을 http://localhost/webapp/mobilehttp://localhost/webapp/areas/mobile을지도 할 수있는 방법이 http://localhost/webapp/areas/mobile/assets/css/styles.css

있습니까 : 실제 URL이기 때문에

<img src="Assets/css/styles.css" /> 

이유는?

덕분에, 랜달

답변

3

내가 생각해 낸 해결책은 단순한 IHTTPModule을 사용하는 것이 었습니다. 그것은 저를위한 URL을 다시 작성합니다. 다음은 BeginRequest 이벤트에 대해 구현 한 메서드입니다.

void BeginRequest(object sender, EventArgs e) 
{ 
    var context = HttpContext.Current; 
    var path = context.Request.Path; 

    // Add Areas to the Mobile path, so we don't have to specify it manually. 
    // This is mainly for handling static resources that you place in areas. 
    if (!path.Contains("Mobile/")) return; 
    if (path.EndsWith(".png") || 
     path.EndsWith(".gif") || 
     path.EndsWith(".css") || 
     path.EndsWith(".js") || 
     path.EndsWith(".htm") || 
     path.EndsWith(".cache")) 
     context.RewritePath(path.Replace("Mobile/", "Areas/Mobile/")); 
} 
1

당신은 아마 같은 것을 할 필요가 :

<img src="../../Mobile/Assets/css/styles.css" /> 

... 현재 디렉토리가 실제로 위치에 따라. 해야 실제 경로가보기에 프로젝트 탐색기에서 (이 경우을 styles.css에) 자산을 끌어 무엇인지 알아

<img src="~Mobile/Assets/css/styles.css" /> 

좋은 방법 및 Visual하자 : 당신은 또한 뭔가를 시도 할 수 있습니다 Studio에서 경로를 만듭니다.

관련 문제