Developer forum

Forum » CMS - Standard features » Inactive paragraph items published via item publisher still accessible via url (google)

Inactive paragraph items published via item publisher still accessible via url (google)

Jacob Storgaard Jensen
Reply

Hi,

My client has a list of paragraph items on one page - these are then published using itempublisher on another page. You can click the paragraph items to see the details, and a custom url is also generated. If the editor disables one of the paragrap items (include/don't include) it is not shown in the published item list BUT the item details page is still accessible via the URL, which means that Google will never delete it from it's index... Anyone have a solution for this?

Solution running 8.6.1.5

(Haven't found any reports of a fix in any release notes after 8.6.1)


Replies

 
Nicolai Høeg Pedersen
Reply

In the template, you can add a check (if it is a Razor template) and return 404 if the paragraph is not active.

Otherwise we need to fix it in item publisher.

if (!Dynamicweb.Content.Paragraph.GetParagraphById(123).ShowParagraph) {
    HttpContext.Current.Response.StatusCode = 404;
    HttpContext.Current.Response.End();
}

 
Jacob Storgaard Jensen
Reply

Hi Nicolai,
If I use that code on my Item Details template (with modified ParagraphId) I get an error:

The name 'HttpContext' does not exist in the current context

Am I wrong to use it on the Details Template?

+ I think this would be something for future fixing in ItemPublisher... Right now I need to recode a quite large template ;-)

 
Nicolai Høeg Pedersen
Reply

System.Web.HttpContext you need to write!

 
Jacob Storgaard Jensen
Reply

Ok, so redirect works – BUT how in the "beep" do I get the paragraphID of the item being published? I'm on a details view of a paragraph item being published?

Trying to set the paragraph ID as a variable to use in the IF you wrote...

 
Jacob Storgaard Jensen
Reply

In the dark here, can't wrap my head around getting that paragraph id to check if is supposed to be "ShowParagraph" or not...

 
Nicolai Høeg Pedersen
Reply

It should be in the tag ItemPublisher:Item.DetailsUrl.PID.

The friendly URL is also rewritten to querystring parameters where you can find the information. You can see here: http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Module-tags/Item-publisher/Details/ItemPublisherItem-DetailsUrl-PID.aspx

 
Jacob Storgaard Jensen
Reply

Hmm... the PID is the ID of the paragraph on which the ItemPublisher is attached, not the ID of the original paragraph item...

The paragraph items are placed in the sitetree as so:

Department1  (page with item publisher attached to module)

AvailableJobs
--- Department1 (page with all the available jobs created as paragraph items - It is here the editor makes the differents jobs inactive, which removes them from the published list, but not from being able to visit them from the google index. Allthough there is already a filter to exclude all jobs where the Boolean "ActiveJob" is false from being published, and it works fine, but there is so many editors comming and going, and the client want the system to be able to handle "Include/Exclude" and return a 404 or go to the published list with a 301, which this code will do as soon as I can get a hand on the ParagraphID from the item being published.)

 

Note: there is no way to create any of the items as page items, this is a running solution with thousands of items.
 

 
Jacob Storgaard Jensen
Reply

Hi Nicolai,

Did you see my last post? :-)

 
Jacob Storgaard Jensen
Reply

Anyone?

 
Jacob Storgaard Jensen
Reply

Again... ANYONE?!

 
Jacob Storgaard Jensen
Reply

Okay, so I have done the below, and it works - BUT are there any large performance issues doing it this way?
It is used on a details view in ItemPublisher...

@{
    var theItemID = GetString("ItemPublisher:Item.Field.Id");
    var sql = "SELECT ParagraphShowParagraph FROM Paragraph WHERE ParagraphItemId = @theItemID";
 
    var currentPublishedItemParagraphVisibility = true;
    
    using (var cmd = Dynamicweb.Database.CreateConnection().CreateCommand())
    {
        cmd.CommandText = sql;
        Dynamicweb.Database.AddStringParam(cmd, "theItemID", theItemID);
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                currentPublishedItemParagraphVisibility = (bool)reader["ParagraphShowParagraph"];
            }
        }
    }

    if (!currentPublishedItemParagraphVisibility) {
        HttpContext.Current.Response.StatusCode = 404;
        HttpContext.Current.Response.End();
    }

}
 
Nicolai Høeg Pedersen
Reply

Nope, and it should only be reached by Google who will no longer index it and forget about it, so it will not have that big impact.

 
Jacob Storgaard Jensen
Reply

Ok,

Well, all active published paragraph items will use the same template on the details view, so it will be reached quite a few times a day... ;-)

 

You must be logged in to post in the forum