Umbraco 9 - Wasn't possible to a get a valid Snapshot getting Website property
Currently going through some hijack routing and I can currently get into my controller, and I can get the current context through the IUmbracoContextFactory.
When I get the content back and cast it as Website to access a property I get this odd error:
InvalidOperationException: Wasn't possible to a get a valid Snapshot
Example code:
public class MyTxtController : UmbracoPageController, IVirtualPageController
{
public MyTxtController(ILogger<UmbracoPageController> logger, ICompositeViewEngine compositeViewEngine) :
base(logger, compositeViewEngine)
{
}
[HttpGet]
public IActionResult Index()
{
var myText = (CurrentPage as Website)?.MyText;
return Content(!string.IsNullOrWhiteSpace(myTxt) ? myTxt : string.Empty;
}
public IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
{
var umbracoContextFactory = actionExecutingContext.HttpContext.RequestServices
.GetRequiredService<IUmbracoContextFactory>();
var content = default(IPublishedContent);
using (var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext())
{
var ctx = umbracoContextReference.UmbracoContext;
content = ctx.Content.GetAtRoot(CultureInfo.CurrentCulture.Name).FirstOrDefault();
}
return content;
}
}
Umbraco 9 - Wasn't possible to a get a valid Snapshot getting Website property
Currently going through some hijack routing and I can currently get into my controller, and I can get the current context through the IUmbracoContextFactory.
When I get the content back and cast it as Website to access a property I get this odd error:
InvalidOperationException: Wasn't possible to a get a valid Snapshot
Example code:
Solved this by following this PR: https://github.com/umbraco/Umbraco-CMS/pull/12088
Would be useful for docs ( https://our.umbraco.com/documentation/reference/routing/custom-routes#custom-route-with-ivirtualpagecontroller ) to include this information
is working on a reply...