Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC ViewPathProvider, database views and Layout
    primarykey
    data
    text
    <p>I am trying to create a CMS using the MVC framework. All was going well, I created my tables to store my ViewData, ViewTitle and virtualPath. I use VirthPathProvider and it looks like this:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Hosting; using CMS; using System.Collections.ObjectModel; using CMS.Components; using System.Web; namespace CMS.Providers { public class PageVirtualPathProvider : VirtualPathProvider { private Directory current { get; set; } private Collection&lt;Directory&gt; directories { get; set; } private Collection&lt;BasePage&gt; pages { get; set; } public override bool FileExists(string virtualPath) { string Path = (VirtualPathUtility.GetDirectory(virtualPath) != "~/") ? VirtualPathUtility.RemoveTrailingSlash(VirtualPathUtility.GetDirectory(virtualPath)) : VirtualPathUtility.GetDirectory(virtualPath); if (IsVirtualPath(Path)) { BasePage oPage = FindPage(virtualPath); if (oPage != null) return true; } bool bExists = base.FileExists(virtualPath); return bExists; } public override VirtualFile GetFile(string virtualPath) { string Path = (VirtualPathUtility.GetDirectory(virtualPath) != "~/") ? VirtualPathUtility.RemoveTrailingSlash(VirtualPathUtility.GetDirectory(virtualPath)) : VirtualPathUtility.GetDirectory(virtualPath); if (IsVirtualPath(Path)) { BasePage oPage = FindPage(virtualPath); if (oPage != null) return new PageVirtualFile(virtualPath, oPage.ViewData.ToArray()); } return base.GetFile(virtualPath); } public override bool DirectoryExists(string virtualDir) { if (IsVirtualPath(virtualDir)) { if (current != null) { if (current.Path.ToLower() != virtualDir.ToLower()) current = new Directory(virtualDir, "53AF0033-4011-4C8F-A14D-7CE9301E264D"); } else { current = new Directory(virtualDir, "53AF0033-4011-4C8F-A14D-7CE9301E264D"); } if (current != null) return true; } return base.DirectoryExists(virtualDir); } public override VirtualDirectory GetDirectory(string virtualDir) { if (IsVirtualPath(virtualDir)) { if (current != null) { if (current.Path.ToLower() != virtualDir.ToLower()) current = new Directory(virtualDir, "53AF0033-4011-4C8F-A14D-7CE9301E264D"); } else { current = new Directory(virtualDir, "53AF0033-4011-4C8F-A14D-7CE9301E264D"); } if (current != null) return new CmsVirtualDirectory(virtualDir, "53AF0033-4011-4C8F-A14D-7CE9301E264D"); } return base.GetDirectory(virtualDir); } public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart) { string Path = (VirtualPathUtility.GetDirectory(virtualPath) != "~/") ? VirtualPathUtility.RemoveTrailingSlash(VirtualPathUtility.GetDirectory(virtualPath)) : VirtualPathUtility.GetDirectory(virtualPath); if (IsVirtualPath(Path)) return null; return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart); } public override string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies) { string Path = (VirtualPathUtility.GetDirectory(virtualPath) != "~/") ? VirtualPathUtility.RemoveTrailingSlash(VirtualPathUtility.GetDirectory(virtualPath)) : VirtualPathUtility.GetDirectory(virtualPath); if (IsVirtualPath(Path)) return Guid.NewGuid().ToString(); return base.GetFileHash(virtualPath, virtualPathDependencies); } private BasePage FindPage(string virtualPath) { string VirtualName = VirtualPathUtility.GetFileName(virtualPath).ToLower(); if (pages == null) { pages = PageManager.getAllPages("53AF0033-4011-4C8F-A14D-7CE9301E264D", false); } BasePage oPage = pages.SingleOrDefault(page =&gt; page.Path.ToLower() == VirtualName); return oPage; } private bool IsVirtualPath(string virtualPath) { string Path = VirtualPathUtility.ToAppRelative(virtualPath); if (directories == null) { directories = DirectoryManager.GetAllDirectories("53AF0033-4011-4C8F-A14D-7CE9301E264D"); } Directory oDir = directories.SingleOrDefault(dir =&gt; dir.Path.ToLower() == Path.ToLower()); if (oDir == null || virtualPath == "~/") return false; // If we don't have directory, return false return true; // Hit only if we are null } } } </code></pre> <p>Now my problem is this: Getting the pages is fine, when they are virtual it returns null as Cache and the FileHash is always a different string, so GetFile is called. My file is returned, but it never finds the Layout.</p> <p>I believe this is because there is no _ViewStart.cshtml because there is no views directory....So how can I force it to use a Layout? I have tried so many things, like getting my virtual pages to inherit from @inherits System.Web.Mvc.WebViewPage, etc, but I still get the same problem....</p> <p>When I navigate to a virtual page, I get this error: Unable to cast object of type 'ASP._Page_Guidelines_index_cshtml' to type 'System.Web.IHttpHandler'.</p> <p>Please help me; I have been stuck on this for 3 weeks....</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload