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

Forums / Developing with Sitefinity / Get content based on URL

Get content based on URL

2 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    23 Nov 2010
    Link to this post
    Hi,

    I am using the url rewriter to fake a URL. I have two pages like so:

    /local-tn/find-a-local-tn.aspx (this page has a list of all the members)

    and

    /local-tn/find-a-local-tn/member-profile.aspx (this is where the individual member profile is displayed, so if you had clicked on a profile the url would actually be:

    /local-tn/find-a-local-tn/member-profile/<memberprofile>.aspx

    I dont want the /member-profile/ part in the url. I know it is possible to show the listview and singleitemview on the same page, but i dont want to as other parts of the pages are customised. Therefore I have the following rule:

    <rule>
                    <url>/local-tn/find-a-local-tn/(?!member-profile\.aspx)([^/])</url>
                    <rewrite>/local-tn/find-a-local-tn/member-profile.aspx?title=$1</rewrite>
                </rule>

    This works, and then on the user control in member-profile.aspx I am trying to match a content item based on the URL that is being passed in the "title" querystring, like so:

    protected override void CreateContentList() {
     
        base.CreateContentList();
     
        ContentManager oContentMgr = new ContentManager(MembersManager.DefaultContentProvider);
     
        if (String.IsNullOrEmpty(Context.Request.QueryString["title"])) {
     
            oRepeater.DataSource = oContentMgr.GetContent();
            oRepeater.DataBind();
     
        }
        else {
     
            ContentProviderBase oProvider = ContentManager.Providers["membersModule"];
     
            IContent oContentItem = oProvider.GetContent("/" + Context.Request.QueryString["title"]);
            if (oContentItem != null) {
     
                itemId = oContentItem.ID;
     
            }
     
        }
     
    }

    But oContentItem is always null. To check I replaced the following line :

    IContent oContentItem = oProvider.GetContent("/" + Context.Request.QueryString["title"]);

    With:

    IContent oContentItem = oProvider.GetContent(new Guid("02b7b88b-23bf-4d5d-a3c5-b58837f6a8c0"));

    Which is a valid member profile guid - and wrote out the URLWithExtension. This was exactly the same as the "title" querystring, so why is GetContent(string url) not working for me?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    23 Nov 2010
    Link to this post
    Hello higgsy,

    There is no overload of ContentManager.GetContent where you can pass the url. You have to create a custom method where you resolve the UrlWithExtension of the IContent and then pass the ID of the item to GetContent method.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered