Custom MVC Root Template Resolver and NullReferenceException
I have Sitefinity 8.0.
I added a Custom Root Template resolver to my project:
public
class
CustomMvcRootResolver : IRootTemplateResolver
public
RootTemplate ResolveTemplate(RootTemplate rootTemplate, RequestContext requestContext,
string
theme)
//var filePath = HostingEnvironment.MapPath("~/RootTemplates/MvcFrontendTemplate.html");
return
rootTemplate.FromString(RootTemplateHtml);
private
const
string
RootTemplateHtml = @"<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv=
""
content-type
""
content=
""
text/html; charset=utf-8
""
/>
<style type=
""
text/css
""
>
body background-color:green; color:#ffffff;
</style>
</head>
<body>
<div
class
=
""
sfPublicWrapper
""
id=
""
PublicWrapper
""
>
</div>
</body>
</html>";
I registered it in the Application_Start of the Global asax file:
PowerTools.Instance
.RootTemplates
.RegisterMvcTemplateResolver<CustomMvcRootResolver>();
I then created a template, choose MVC only, created a page based on that template (I didn't add any widgets to the page), published the page, then chose View Page from the Pages screen.
I get the following error:
[NullReferenceException: Object reference not set to an instance of an object.]
Telerik.Sitefinity.Web.PageRouteHandler.handler_PreRenderComplete(Object sender, EventArgs e) +913
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +121
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1155
Anyone know why this is happening?
My code above is based on the sample code here:
Has anyone been able to successfully implement a custom MVC Root Template resolver?
I really need to get this to work...
The code in the sample is not entirely correct.
The solution is: <head> needs the runat="server" attribute. Also, delete the <title> element.