So,
I have managed to pull my content for a view from the database.
Now my issue is that they are being pulled back only as the HTML in the table (without it's layout).
Can anyone explain to me why?
here is my Controller:
and here is my PathProvider:
and this is the VirtualFile
and if it pleases anyone, this is my where i register my PathProvider:
as usual, any help is appreciated....
/r3plica
I have managed to pull my content for a view from the database.
Now my issue is that they are being pulled back only as the HTML in the table (without it's layout).
Can anyone explain to me why?
here is my Controller:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMS.Components;
using Core;
using Core.Components;
using CMS;
using System.Collections.ObjectModel;
namespace Cogs.Controllers
{
[Authorize]
[ProfileFilter]
public class PageController : Controller
{
#region Properties
IProfile oProfile
{
get { return (IProfile)Session["oProfile"]; }
}
#endregion
//
// GET: /Pages/
public ActionResult Index(string url)
{
Collection<BasePage> oPages = PageManager.getAllPages(oProfile.CompanyId, false);
BasePage p = oPages.SingleOrDefault(page => page.Path.ToLower().Equals(url.ToLower()));
if (p != null)
{
return View(System.IO.Path.GetFileNameWithoutExtension(p.Path));
}
else
{
return View();
}
}
public ActionResult View(int Id)
{
Page oPage = new Page(Id, oProfile.CompanyId);
return View(System.IO.Path.GetFileNameWithoutExtension(oPage.Path));
}
}
}
and here is my PathProvider:
C#:
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
{
public override bool FileExists(string virtualPath)
{
BasePage oPage = FindPage(virtualPath);
if (oPage == null)
{
return base.FileExists(virtualPath);
}
else
{
return true;
}
}
public override VirtualFile GetFile(string virtualPath)
{
BasePage oPage = FindPage(virtualPath);
if (oPage == null)
{
return base.GetFile(virtualPath);
}
else
{
return new PageVirtualFile(virtualPath, oPage.ViewData.ToArray());
}
}
public override VirtualDirectory GetDirectory(string virtualDir)
{
return base.GetDirectory(virtualDir);
}
private BasePage FindPage(string virtualPath)
{
Collection<BasePage> oPages = new Collection<BasePage>();
if (HttpContext.Current.Session != null && HttpContext.Current.Session["Pages"] == null)
{
Collection<BasePage> oAll = PageManager.getAllPages("53AF0033-4011-4C8F-A14D-7CE9301E264D", false);
HttpContext.Current.Session.Add("Pages", oAll);
}
if (HttpContext.Current.Session != null)
{
oPages = (Collection<BasePage>)HttpContext.Current.Session["Pages"];
}
BasePage oPage = oPages.SingleOrDefault(page => page.ActualPath.ToLower() == virtualPath.ToLower());
return oPage;
}
}
}
and this is the VirtualFile
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Hosting;
using System.IO;
namespace CMS
{
class PageVirtualFile : VirtualFile
{
private byte[] data;
public PageVirtualFile(string virtualPath, byte[] data) : base (virtualPath)
{
this.data = data;
}
public override System.IO.Stream Open()
{
return new MemoryStream(data);
}
}
}
and if it pleases anyone, this is my where i register my PathProvider:
C#:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
HostingEnvironment.RegisterVirtualPathProvider(new PageVirtualPathProvider());
}
as usual, any help is appreciated....
/r3plica