1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Absolute URL to SingleItem NewsView

Absolute URL to SingleItem NewsView

5 posts, 0 answered
  1. LBrinley
    LBrinley avatar
    59 posts
    Registered:
    29 Dec 2005
    05 Jun 2009
    Link to this post
    I have need to generate the absolute url to a single item NewsView from the item's associated IContent object.  Unfortunately, I am able only to retrieve a limited relative url from the IContent object (via its associated NewsManager), such as "/the_news_item_title"  from the CMSContentBase.  I've hardcoded the remainder of the absolute url as a workaround.  I would like to build this absolute url programmatically.

    I've previously noticed that your NewsView ListPageMaster.ascx achieves this end by populating a HyperLink control having an ID of "fullContent1" -- as though the control were databound in the repeater. However,  since 'fullContent1' does not exist as a field in the CMSContentBase or the General Content MetaData associated with the News module, you cannot be databinding this control directly, but rather must be using some procedure to build the necessary absolute url and using it to populate the 'fullContent1' HyperLink control.  In short, how do you do it?

    I have considered that I could iterate over the CMS Pages looking for NewsView controls, and, when found, check to see if the current NewsView 'housed' my selected IContent object, but it doesn't seem to me that this brute force approach is very scalable.  I'm hoping that your method is both more scalable and elegant. 
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    05 Jun 2009
    Link to this post
    if my understanding is correct, the reason the newsview has a generic url is to allow the article to be displayed in multiple newsviews (if so desired). additionally, tying the news article to a specific page would cause you to have to update every single news item if you decided to move or rename the page that holds your newsview...

    instead, having the url only contain the information for the article lets you move the url from location to location (or domain to domain) without breaking the newsview control...

    similarly, the missing suffix (no aspx in the url) lets you use extentionless urls or even html or php or whatever your site may be using.

    that being said, if you wanted to do it programmatically, I would recommend putting the key elements in a database or xml file, or some other storage location (like a static class with a const string property) so that when you build the url you can do something like

    var url = Settings.NewsUrlPrefix + newsitem.Url + Settings.NewsUrlSuffix;

    where Settings is a wrapper to whereever this information is stored. this way if your newsview page moves, you can simply update the location.

    I hope this is helpful. if there is indeed a more elegant solution, I too would like to know it!

    thanks
  3. LBrinley
    LBrinley avatar
    59 posts
    Registered:
    29 Dec 2005
    05 Jun 2009
    Link to this post
    SelArom,

    I agree with your comments and understand the rationale behind the limited relative url in the CMSContentBase.  However, at some point, we need a usable url to the content.

    The Sitefinity ListPageMaster.ascx file is able to derive the correct url to each specific content item's SingleItem NewsView page, no matter where that SingleItem page resides or where the ListPage NewsView control is placed within the site.  This is the 'magic' I'm after -- not 'tying the article to a specific page'.  I just hope the solution Sitefinity employs is more efficient/elegant than the 'iterate over all the pages looking for the current news item' solution that has occurred to me.

    Pleasure as always to hear your $0.02.
  4. LBrinley
    LBrinley avatar
    59 posts
    Registered:
    29 Dec 2005
    05 Jun 2009
    Link to this post
    All,

    Please ignore this question.  I simply forgot that when configuring an instance of the ListPageMaster.ascx control, you must specify whether the SingleItem page should be automatically generated or a specific page should be used.  Clearly, it is this instance property that allows the particular NewsView ListPage to find its associated SingleItem page for each item -- not some 'magic' Sitefinity process.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 Jun 2009
    Link to this post
    Hello iVillageIdiot,

    Currently the easiest way to get the absolute url is to get the relative one and append it the the page url where your control is located. Otherwise you should loop through all pages and find the control by ID.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
5 posts, 0 answered