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

News URL's

10 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Hi all,

    I have a couple of questions about the news modules. I want the URL structure of the website im developing to appear like:

    - /news-events.aspx
    - /news-events/2009 (show all news articles in 2009)
    - news-events/2009/<Article>.aspx

    To achieve the last point I've changed the provider string in the config file to:

    <add name="News" urlRewriteFormat="[Publication_Date]/[Title].aspx" urlDateTimeFormat="yyyy" urlWhitespaceChar="-" visible="False" defaultMetaField="Title" securityProviderName="" allowVersioning="True" allowWorkflow="True" applicationName="/News" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.News.Data.DefaultNewsProvider, Telerik.News.Data"/>

    However, the part I can't figure out is the news archive control. Clicking upon a year in this control renders a url like :

    /news-events.aspx?Year=2009

    Is it possible to change this so that it renders:

    /news-events/<year>

    Of course, the news view control will need to recognise the new url structure?

    Thanks in advance
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 Aug 2010
    Link to this post
    Hello Alastair,

    You can use AdvancedURl Rewriter - UserManual, page 195 , otherwise you have to override NewsView control - CreateChildControls() method, because the filtering will not occur with the new tag

    sample

    if (!String.IsNullOrEmpty(year))
    {
        int year = int.Parse(year);
        int month = 0;
     
        ContentFilterStatement filterStartDate;
        ContentFilterStatement filterEndDate;
     
        if (month != null && month >= 1 && month <= 12)
        {
                // filter by both month and year you can change the DateTime here and use any other valid DataTime format to make the filtering
                 filterStartDate = new ContentFilterStatement(
                "Publication_Date",
                String.Concat("\"", new DateTime(year, month, 1, 0, 0, 0).ToString(), "\""),
                ContentFilter.Condition.GreaterOrEqual,
                ContentFilter.JoinType.And);
            filterEndDate = new ContentFilterStatement(
                "Publication_Date",
                String.Concat("\"", new DateTime(year, month, DateTime.DaysInMonth(year, month), 23, 59, 59).ToString(), "\""),
                ContentFilter.Condition.LessOrEqual,
                ContentFilter.JoinType.And);
        }

    }


    All the best,
    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
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Hi Ivan,

    Thanks for your response.

    The sample you provided, what file is this code being added to?

    Also, the sample you provided enables sitefinity to match the url and content, but in terms of generating the correct urls in the news archive control, will i need to create my own control? Obviously the standard archive control appends the year in a querystring which i want to avoid.

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 Aug 2010
    Link to this post
    Hi Alastair,

    The sample you provided, what file is this code being added to?

    "you have to override NewsView control - CreateChildControls() method, because the filtering will not occur with the new tag"

    The link of the ContentArchive contains the date and you can escape this in the browser's bar by using url rewriting or overriding BindHierarchicalArchive of NewsArchive control and changing the NavigateUrl property.

    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
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Ivan,

    Apologies, but in your first post you said:

    You can use AdvancedURl Rewriter - UserManual, page 195 , otherwise you have to override NewsView control - CreateChildControls() method, because the filtering will not occur with the new tag

    Indicating that I could use the AdvancedURI rewriter OR I could override the NewsView control - are you in fact stating I need to do both?

    Could you also please let me know whether I need to develop a custom news archive control that will render the correct hyperlinks?

    thanks again
    higgsy


  6. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Hi Ivan,

    Having re-read your reply, can you please confirm whether I am right in saying the following:

    1) I Should create a control which inherits from the NewsArchive control, then override the BindHierarchicalArchive method. 

    2) I should create a control which inherits from the NewsView control, then override the CreateChildcontrols method. Alternatively I could use url rewriting to do something like:

    /news/2009/ points to news.aspx?Year=2009

    If i am correct, could you please just provide a short snippet for overriding the BindHierarchicalArchive method. I cant find any information on it whatsoever, even within the documentation.

    Thanks again
    higgsy
  7. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Hi Ivan,

    I've overridden the BindHierarchicalArchive method of the News Archive control using the following code:

    protected override void BindHierarchicalArchive(Telerik.Web.UI.RadTreeView tree) {
     
        base.BindHierarchicalArchive(tree);
     
        foreach (Telerik.Web.UI.RadTreeNode oNode in tree.GetAllNodes()) {
     
            oNode.NavigateUrl = this.ArchivePageUrl.Replace(".aspx","") + "/" + oNode.FullPath;
     
        }
     
     
    }

    This means the News Archive Control is now rendering the url's as I want them.

    /news-events/news/2008
    /news-events/news/2009
    /news-events/news/2010

    However, clicking on this results in a 404 even with the UrlRewriting code in place:

    <telerik>
        <urlrewrites ignoreCase="true">
            <rule>
                <url>/News-Events/News/(.*)/</url>
                <rewrite>/news-events/News\.aspx?Year=2010</rewrite>
            </rule>
        </urlrewrites>

    Can you please help? I've seen a few posts from people stating they could never get it working in IIS7 - so i dont want to waste time if I have to override the CreateChildControls method of the news view instead???

    Thanks
    higgsy
  8. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Ivan,

    I should also state that the following URL rewrite DOES work:

    <urlrewrites ignoreCase="true">
        <rule>
            <url>/News-Events/News.aspx</url>
            <rewrite>/news-events.aspx</rewrite>
        </rule>
    </urlrewrites>

    But simply changing that to:

    <urlrewrites ignoreCase="true">
        <rule>
            <url>/News-Events/News/</url>
            <rewrite>/news-events.aspx</rewrite>
        </rule>
    </urlrewrites>

    Prevents it from working.....any ideas?

    higgsy

  9. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    31 Aug 2010
    Link to this post
    Ivan,

    I have only one final question left now, as most of it now appears to be working:

    The followign rule allows me to view url's filtered by year, like so:

    /news-events/news/2009/
    /news-events/news/2008/

    <rule>
        <url>/News-Events/News/(.*)/</url>
        <rewrite>/news-events/news.aspx?Year=$1</rewrite>
    </rule>

    However, if i then click on a news article to read the entire story, i get the following error message:

    Input string was not in a correct format.


    This is because the url /news-events/news/2010/mystory.aspx is also matching the rule, and is therefore rewriting the url to:

    /news-events/news.aspx?Year=mystory.aspx which is obviously incorrect.

    I added a rule prior to that one, so the entire urlrewrites looks like so:

    <urlrewrites ignoreCase="true">
        <rule>
            <url>/News-Events/News/(.*)/(.*)</url>
            <rewrite>/news-events/news.aspx?Year=$1&Title=$2</rewrite>
        </rule>
        <rule>
            <url>/News-Events/News/(.*)/</url>
            <rewrite>/news-events/news.aspx?Year=$1</rewrite>
        </rule>
    </urlrewrites>

    This works, apart from the fact the rewriteurl in the first rule is not passing the right parameters to the news.aspx page so that it can show the right article.

    Can you please help with this very last bit.

    Thanks
    higgsy
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Sep 2010
    Link to this post
    Hello Alastair,

    The problem is that both of the regular expressions overlap in a way. What happens is that the UrlRewriter finds the first matching rule and in the case it is the first declared rule. CmsHttpModule takes the current request and the url is already resolved based on the request.

    You can use this regular expressions online tool to test if the rules match requested urls.


    Regards,
    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
Register for webinar
10 posts, 0 answered