Last post Mar 29, 2012 01:57 PM by thinkrajesh
Mar 28, 2012 08:47 AM|chris_abyi|LINK
Mar 28, 2012 02:02 PM|BrockAllen|LINK
ASP.NET vistualizes the file system with something called a
virtual path provider. You could implment this API and then ASP.NET will call into you to load the file (instead of looking on disk). Your implementation could then load it from a database or anywhere.
Mar 28, 2012 06:28 PM|thinkrajesh|LINK
Virtual path provider is one way, also you can do this without any tweaks as your views will be within your app(as mentioned in your questiion).... Since by default your views are not compiled. So, you can still deploy ascx/aspx files onto the server without
redeploying your webapp...
Apart from this if you just need a way to organize your folders as per convenience, you can just write a ViewEngine and specify the folder locations from which to load the view....
Mar 29, 2012 12:08 PM|chris_abyi|LINK
Thanks for the great replies. Probably I have to clarify what I need: I want to get a part of my views from a directory outside the wwwroot, but still on the same server, not from a database, neither from a zip-file. Defining a customized ViewEngine seems
to just offer a change of paths within the web app directory. Creating a VirtualPathProvider is not that easy, although I think it's actually the best solution. I wonder if there's a tutorial available which does NOT deal with loading views from a database,
but just from another directory in the file system. I would appreciate any hints on that..
Thanks a lot again for your help,
Mar 29, 2012 01:51 PM|BrockAllen|LINK
Oh if your views are just in some other directory then you can
create a virtual directory in IIS -- easier than a VPP.
Mar 29, 2012 01:57 PM|thinkrajesh|LINK
I think you can still use the VirtualPathProvider, to load views from another directory in the file system (cause for VPP, it doesn't matter from where your views are loaded).
Here's a sample of loading a view from a "DLL". You can use the ssame concept for loading a view from any of the filessytem on your webserver as long as they are accessible...
The important thing is when you return view from your controller you stick to this pattern.. and you need to give the full name with extension.. You can wrap this in some helper which buildsup your view path...
return View("/yourviewapp/yourpathtofiew/FULLNAME_YOUR_VIEW.aspx"); // This view should be mapped as a virtual directory or app in IIS.