I have a standalone WebService / WebApplication using the wonderful Service Stack.
My views are embedded in DLLs as well as images. I am using ResourceVirtualPathProvider code from GitHub. It finds the index page and layouts correctly, but cannot find the embedded images / css (perhaps obviously).
How do I configure the Razor plugin to search for path providers. I checked debug mode and path providers found all css and images. They just don't get routing.
EDIT
I tried to set the AppHost VirtualPathProvider property to the same provider with which I configured the RazorFormat plugin, but to no avail.
LAST EDIT
Thanks to Mythz's answer, I now got this working and provided the solution below:
Firstly (and I had it before), I used the Embedded code from GitHub to create a virtual resource path for suppliers, directories and files.
Implemented by 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
Configure everything in my configuration function (the fact that it is static is unique to my script, but it is effectively called from the regular AppHost Configure function)
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 }); config.AppHost.CatchAllHandlers.Add((httpMethod, pathInfo, filePath) => { IVirtualFile file = _pathProvider.GetFile(pathInfo); if (file == null) return null; return new VirtualFileHandler(file); }); }
source share