How can I get MVC 5 to render a View that is physically outside the Web Application Folder?

438 Views Asked by At

I am using ASP.NET MVC5 and I would like to render a view from a folder that is outside the application folder. I tried registering my own custom the VirtualPathProvider and I even created my own VirtualPathProviderViewEngine to support rendering pure html pages. I have the latter working but cannot get the former to work. When I navigate to the route in question, I want MVC to check the internal Views folder for the View and then if it is not found I want it to look in the external folder.

When I step through the code, FileExists gets called for files that are in the Views folder and then the ViewEngine code runs but for a View that lives externally, the FileExists check runs and then I get a 404 on the screen. It does not ever get into the ViewEngine code. I know I am missing something simple here.

I am attaching a screenshot of what the sample folder structure would be. Any help would be greatly appreciated. FolderStructure

1

There are 1 best solutions below

3
Laurent Lequenne On

You can override the VirtualPathProvider and the VirtualFile Check this link for an Example