Loading external views in ASP.NET MVChttp://forums.asp.net/t/1786167.aspx/1?Loading+external+views+in+ASP+NET+MVCThu, 29 Mar 2012 12:57:32 -040017861674903266http://forums.asp.net/p/1786167/4903266.aspx/1?Loading+external+views+in+ASP+NET+MVCLoading external views in ASP.NET MVC Hey there, in order to ensure flexibility and update ascx/aspx files on my server without a need to redeploy my webapp and without the risk of files to be overwritten, I want to store them externally, i.e. not in the asp.net MVC webapp. Nevertheless, I want them to be part of the app and protected via asp.net authentication, i.e. they should be loaded from a controller method with the [Authorize] tag. Is there any means to achieve this? Thanks very much in advance, Christian 2012-03-28T07:47:42-04:004904037http://forums.asp.net/p/1786167/4904037.aspx/1?Re+Loading+external+views+in+ASP+NET+MVCRe: Loading external views in ASP.NET MVC <p>ASP.NET vistualizes the file system with something called a <a href="http://support.microsoft.com/kb/910441"> virtual path provider</a>. 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.</p> 2012-03-28T13:02:43-04:004904607http://forums.asp.net/p/1786167/4904607.aspx/1?Re+Loading+external+views+in+ASP+NET+MVCRe: Loading external views in ASP.NET MVC <p>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. &nbsp;So, you can still deploy ascx/aspx files onto the server without redeploying your webapp...</p> <p>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....</p> <p></p> 2012-03-28T17:28:59-04:004906059http://forums.asp.net/p/1786167/4906059.aspx/1?Re+Loading+external+views+in+ASP+NET+MVCRe: Loading external views in ASP.NET MVC <p>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..</p> <p>Thanks a lot again for your help,</p> <p>Christian</p> 2012-03-29T11:08:54-04:004906309http://forums.asp.net/p/1786167/4906309.aspx/1?Re+Loading+external+views+in+ASP+NET+MVCRe: Loading external views in ASP.NET MVC <p>Oh if your views are just in some other directory then you can <a href="http://technet.microsoft.com/en-us/library/cc771804%28v=WS.10%29.aspx"> create a virtual directory</a> in IIS -- easier than a VPP.</p> 2012-03-29T12:51:52-04:004906330http://forums.asp.net/p/1786167/4906330.aspx/1?Re+Loading+external+views+in+ASP+NET+MVCRe: Loading external views in ASP.NET MVC <p>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).</p> <p>Here's a sample of loading a view from a &quot;DLL&quot;. &nbsp;You can use the ssame concept for loading a view from any of the filessytem on your webserver as long as they are accessible...</p> <p><a href="http://stackoverflow.com/questions/236972/using-virtualpathprovider-to-load-asp-net-mvc-views-from-dlls">http://stackoverflow.com/questions/236972/using-virtualpathprovider-to-load-asp-net-mvc-views-from-dlls</a></p> <p></p> <p>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 &nbsp;your view path...</p> <p><span>return View(&quot;/yourviewapp/yourpathtofiew/FULLNAME_YOUR_VIEW.aspx&quot;); &nbsp;// This view should be mapped as a virtual directory or app in IIS.</span></p> <p><span><br> </span></p> <p></p> <p></p> <p></p> 2012-03-29T12:57:32-04:00