2013-07-04 5 views
3

멋진 서비스 스택을 사용하여 자체 호스팅되는 WebService/WebApplication을 보유하고 있습니다.ServiceStack 포함 된 이미지/CSS가 포함 된 면도기 (자체 호스팅)

내보기가 DLL에 포함되어 있으며 이미지도 마찬가지입니다. 나는 GitHub에서 ResourceVirtualPathProvider 코드를 사용하고 있습니다. 그것은 인덱스 페이지와 레이아웃을 정확하게 찾았지만 임베디드 이미지/css (아마 명백하게)를 찾을 수 없습니다.

경로 제공 업체를 검색하기 위해 Razor 플러그인을 구성하는 방법은 무엇입니까? 디버그 모드에서 검사했고 경로 공급자가 모든 CSS와 이미지를 찾았습니다. 그들은 그냥 라우팅되지 않습니다. 내가 가진 RazorFormat 플러그인을 구성 같은 공급자에게 AppHost의 VirtualPathProvider 속성을 설정했지만, 아무 소용이있다

편집 할 수 있습니다.

마지막 편집 Mythz의 반응에

감사합니다, 지금이 작업을 가지고 아래의 솔루션을 제공했다 : 첫째

  1. 을 (내가 전에이 있었다), 나는 Embedded 코드를 사용 GitHub에서 리소스 가상 경로 공급자, 디렉터리 및 파일을 만듭니다.

  2. 는 VirtualFileHandler을 구현 :

    public sealed class VirtualFileHandler : IHttpHandler, IServiceStackHttpHandler 
    { 
    private IVirtualFile _file; 
    
    
    /// <summary> 
    /// Constructor 
    /// </summary> 
    /// <param name="file">File to serve up</param> 
    public VirtualFileHandler(IVirtualFile file) 
    { 
        _file = file.ThrowIfDefault("file"); 
    } // eo ctor 
    
    
    public bool IsReusable { get { return false; } } 
    
    
    public void ProcessRequest(HttpContext context) 
    { 
        ProcessRequest(new HttpRequestWrapper(null, context.Request), 
            new HttpResponseWrapper(context.Response), 
            null); 
    } // eo ProcessRequest 
    
    public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName) 
    { 
        try 
        { 
         response.ContentType = ALHEnvironment.GetMimeType(_file.Extension); 
         using (Stream reader = _file.OpenRead()) 
         { 
          byte[] data = reader.ReadFully(); 
          response.SetContentLength(data.Length); 
          response.OutputStream.Write(data, 0, data.Length); 
          response.OutputStream.Flush(); 
         } 
        } 
        catch (System.Net.HttpListenerException ex) 
        { 
         //Error: 1229 is "An operation was attempted on a nonexistent network connection" 
         //This exception occures when http stream is terminated by the web browser. 
         if (ex.ErrorCode == 1229) 
          return; 
         throw; 
        } 
    } // eo ProcessRequest 
    } // eo class VirtualFileHandler 
    
  3. 내 설정 기능 (이 정적 사실 내 시나리오에 고유하지만, 효과적으로 일반 AppHost의 Configure 함수에서라고)

    protected static void Configure(WebHostConfiguration config) 
    { 
        _pathProvider = new MultiVirtualPathProvider(config.AppHost, 
                   new ResourceVirtualPathProvider(config.AppHost, WebServiceContextBase.Instance.GetType()), 
                   new ResourceVirtualPathProvider(config.AppHost, typeof(ResourceVirtualPathProvider))); 
        config.Plugins.Add(new RazorFormat() 
        { 
         EnableLiveReload = false, 
         VirtualPathProvider = _pathProvider 
        }); 
    
    
        /* 
        * We need to be able to locate other embedded resources other than views, such as CSS, javascript files, 
        * and images. To do this, we implement a CatchAllHandler and locate the resource ourselves 
        */ 
        config.AppHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => 
        { 
         IVirtualFile file = _pathProvider.GetFile(pathInfo); 
         if (file == null) 
          return null; 
    
         return new VirtualFileHandler(file); 
        }); 
    } // eo Configure 
    
    에서

    구성된 모든

답변

관련 문제