Was wondering if there's a way i can exclude the Preview mode within the IContentFinder as currently when you clicked on the preview button on a content node, it just shows 404 not found due to the path does not contains a language from the implementation above.
I've come across this same problem, and I've come up with an admittedly hacky solution to it.
When a node is previewed, I take the path and check to see if it can be parsed as an integer, as the URL is of the structure "http://yoursite.com/1234.aspx". If the first part is an integer, I treat it as a preview item.
The key part is the call to GetById.. One of the overload signatures has a bool property that allows you to state if you want the preview item. Set this to true, and you get the preview item as IPublishedContent.
var path = contentRequest
.Uri
.GetAbsolutePathDecoded();
var parts = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
int nodeId;
if(parts.Length == 1 && int.TryParse(parts[0], out nodeId))
{
var contentCache = UmbracoContext
.Current
.ContentCache;
var content = contentCache.GetById(true, nodeId);
contentRequest.PublishedContent = content;
return true;
}
As I said above, I don't feel that this is as clean a solution as it could be, so I'd love to hear if there is a better way of doing this.
Exclude Preview mode from IContentFinder
Hi All,
I'm using IContentFinder similar to the implementation below https://gist.github.com/alindgren/4f8e47d9b2d769137be3
Was wondering if there's a way i can exclude the Preview mode within the IContentFinder as currently when you clicked on the preview button on a content node, it just shows 404 not found due to the path does not contains a language from the implementation above.
Appreciate any help
Thanks a million
I've come across this same problem, and I've come up with an admittedly hacky solution to it.
When a node is previewed, I take the path and check to see if it can be parsed as an integer, as the URL is of the structure "http://yoursite.com/1234.aspx". If the first part is an integer, I treat it as a preview item.
The key part is the call to GetById.. One of the overload signatures has a bool property that allows you to state if you want the preview item. Set this to true, and you get the preview item as IPublishedContent.
As I said above, I don't feel that this is as clean a solution as it could be, so I'd love to hear if there is a better way of doing this.
You could also preview all the content of the website. Than the IContentFinder should not return a 404. See this example: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78849-preview-all-content#comment-252857
Jeroen
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.