I am currently working on a project which features a plugin-like system. Once the web project starts up it looks for plugin dlls and build up the GUI. The dlls contain embedded views, and embedded resources like pictures or javascripts.
I use RazorGenerator(VS Plugin) to generate the cs files from the views, The build action of the views is set to 'embedded resource' and the custom tool is set to 'RazorGenerator'
I use a custom Virtual Path Provider (a very similar to this one)
I register my virtual path provider with this workaround i found on the net (it is a must since it is not working as intented if i dont use this):
var assemblyResourceProvider = new AssemblyResourceProvider(); var hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null); if (hostingEnvironmentInstance == null) return; var mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static); if (mi == null) return; mi.Invoke(hostingEnvironmentInstance, new object[] { assemblyResourceProvider });
I use this at my RouteConfig.cs to make the embedded script and picture files work:
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|png|jpg|exe)(/.*)?" });
I add these lines (there are more) to my web.config to tell asp to use my path provider for my embedded sources:
<add name="AspNetStaticFileHandler-PNG" path="*.png" verb="GET,HEAD" type="System.Web.StaticFileHandler"/>
I use the Boc.Web.PrecompiledViews dll to register the path attributes generated by RazorGenerator
BoC.Web.Mvc.PrecompiledViews.ApplicationPartRegistry.Register(assembly);
Everything is working as intended in Visual Studio. The views and resources embedded in a dll are showing and working flawlessly. I also use IIS 7.5 to run my web app from Visual Studio. All of the possibilities work:
- it works if i give the virtual path generated by Razor Generator (ex: "~/Views/ViewTest/Test)
- it works if i give the Dll resources path which uses my resourceprovider (ex: "DllResources/ViewTest.dll/Views/ViewTest/Test.cshtml)
However, after i deploy my web app and run it using IIS 7.5, the Views(only the views!) are not showing! If i address the views with the virtual path (option 1), IIS gives this error message:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
if i address the views with the DllResources path (option 2), IIS gives this error message:
The file '/Views/ViewTest/DllResources/EmbeddedResourceTest/Views/ViewTest/Test.cshtml' has not been pre-compiled, and cannot be requested.
I dont know what to do now to make it work. I have tried to replace every single step with other solutions. The result is still the same. Flawlessly working in VS, but the views are not showing after deployment.
Is it some config for the IIS what is missing? am i missing something from the web.config? Please help me with this issue.
Thanks, Norbert