More in this section

Forums / Developing with Sitefinity / Generate url for a forum post?

Generate url for a forum post?

10 posts, 0 answered
  1. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    07 Apr 2009
    Link to this post

    I'm trying to make some custom controls for Sitefinity (and loving it compared to most other CMS's I've used over the years), and it was easy enough to make a custom list of recent blog entries plus url links to them, but I'm not really sure if it's possible to do the same for forum posts?

    What I want it to be able to list the latest ten forum posts on the front page with a link to them as well in a custom user control.  I can get the latest forum posts with this code:

    // Get recent posts
    IList recentPosts = m_forumManager.GetRecentPosts(0, this.MaxNumberOfPosts);

     

     

    What I can't figure out is the url to assign to each individual post, similar to the .UrlWithExtension property for a blog entry with which you can get a hardcoded url.

    Can anyone at least confirm that you can or can't make a url linking to a specific forum thread or post, such as http://xxx.mysite.xxx/forums/threadguid.aspx?id=postguid ???

    Kevin.

     

  2. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    07 Apr 2009
    Link to this post
    Just as a follow up I can see that Telerik's site has fixed urls when I move my mouse over a forum thread, but when I do the same on my own installation (3.6), all I see is some javascript postback code ... I really want to have fixed urls if that's possible.  It seems it's possible, I just can't see anything in the config to change this.
  3. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    11 Apr 2009
    Link to this post

    Anyone?  I would have thought that other people would want search engine friendly URLs on their site?  Looking through the web.config file, I don't even see anything for configuring the Forum entries like you can with Generic Content based modules (example below):

     

    <

     

    add name="Blogs" urlRewriteFormat="[Publication_Date]/[Title].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Title" applicationName="/Blogs" allowVersioning="True" allowComments="true" commentsModeration="false" allowLocalization="False" localizationProviderName="" allowWorkflow="False" securityProviderName="" versioningProviderName="" connectionStringName="GenericContentConnection" type="Telerik.Blogs.Data.DefaultBlogProvider, Telerik.Blogs.Data"/>

    I can see that Telerik has nice search engine friendly urls for all their forums posts ... did you completely change the forum provider to do this?  For example, the Modules forum has this url, and each post has a similar normal url rather than working via postback:

    http://www.sitefinity.com/support/forums/forum/b1041S-cbc.aspx
    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-cadgat.aspx

    Kevin.

  4. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    13 Apr 2009
    Link to this post
    Hello KEVIN TOWNSEND,

    You can use this url to link to specific thread/post (you supply the thread and mode query parameters):
    // your page where SingleThread of Forums control is located 
    string singleThreadPage = "~/yourForumPage.aspx"
     
    ForumManager manager = new ForumManager(); 
     
    IList forums = manager.GetForums(true); 
     
    foreach (IForum forum in forums) 
        IList posts = forum.Posts; 
        foreach (IPost post in posts) 
        { 
            Guid threadID = post.Thread == null ? post.ID : post.Thread.ID; 
            string threadUrl = string.Concat(singleThreadPage, "?mode=singleThread&thread="
                  threadID); 
        } 

    You can make the urls friendly using the Url Rewriting feature of Sitefinity:
    1. Setup the Url Rewriter - follow the steps in the User Manual - section Url Rewriting.
    2. Add your custom rewriting rules. For example this rule will allow you to request your thread page with link in this form - http://server.com/yourForumPage/<id of the thread>.aspx
    <urlrewrites> 
        <rule> 
            <url>/yourForumPage/([^\.]*)\.aspx</url> 
            <rewrite>/yourForumPage.aspx?mode=singleThread&amp;thread=$1</rewrite> 
        </rule> 
    </urlrewrites> 


    Regards,
    Parvan
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    14 Apr 2009
    Link to this post
    Parvan:

    Thanks for the helpful reply.  That's exactly what I was looking for.

    Kevin.
  6. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    14 Apr 2009
    Link to this post
    I just tested this out, and it works perfectly in a custom control (which was the main situation I wanted it for ... thanks). 

    I was wondering, though, if there is a way to configure the built in forum controls to use a standard URL rather than a postback?  For example, when I go to the page containing a list of all available forums (using the ForumList control), and I mouse over a forum I get the following postback causing url:

    javascript:__doPostBack('ctl00$Content$ForumList1$ctl00$ctl00$forumsRepeater$ctl02$inner$ctl02$btnOpenForum','')

    Is there a straight-forward way to tell the built in forum controls (ForumList, SingleThread, etc.) to use a URL instead?  I'm just afraid that these pages won't get properly indexed by search engines the way they are at present.  If not, is there a workaround I could implement?

    I'd really suggest changing the default behaviour of these controls in a future version to be more search engine friendly by defaulting to URLs rather than only seeing postbacks.

    Kevin.
  7. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    17 Apr 2009
    Link to this post
    Hi Kevin,

    Forum controls work with postback. If you want to use an url you need to extend the Forums controls and modify their buttons.
    I have attached extended sample controls for the SingleForum, SingleThread and ForumList controls.
    They have the same functionality as the original Forum controls but their buttons use an url instead of postback.

    They will work only with Sitefinity 3.6 SP1.

    Setup:

    1. Upgrade your site to Sitefinity 3.6 Sp1
    2. Put the attached files to the App_Code folder of your site.
    3. Open and edit your web.config file:
    <toolboxControls> 
    ... 
        <add name="CustomForumList" section="My Forums Controls" type="Telerik.Forums.WebControls.CustomForumList, App_Code" 
                  description="CustomForumList" /> 
        <add name="CustomSingleThread" section="My Forums Controls" type="Telerik.Forums.WebControls.CustomSingleThread, App_Code" 
                  description="CustomSingleThread" /> 
        <add name="CustomSingleForum" section="My Forums Controls" type="Telerik.Forums.WebControls.CustomSingleForum, App_Code" 
                            description="CustomSingleForum" /> 
               
    </toolboxControls> 

    4. Use the controls located at the My Forums Controls section of your toolbox instead of the original Forum controls located at Forums section.

    Don't hesitate to contact us if you have other questions.

    Sincerely yours,
    Parvan
    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.
  8. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    23 Apr 2009
    Link to this post
    Sorry for the late reply, and thanks for the update and the .rar file with the code.  The CustomForumList seems to work as expected, but I'm getting errors with both the CustomSingleForum and CustomSingleThread when I try to add them to the page.  (I've upgraded to 3.6 SP1 as well)

    When I add CustomSingleForum to the page, I get a NullReferenceException  on this line:

    ((

    LinkButton)this.container.BackToForumsButton1).Attributes.Add("href",
    UrlPath.ResolveUrl(this.allForumsPage));

     

    Specifically, it seems to be the 'this.allForumsPage'.  I'm assuming this is because I haven't yet added the url the appropriate property, but if this makes its way into a future version you might want to fix this not to throw an exception as soon as you drop it onto the page.  I had to switch to 'classic' mode to even edit the control properties.

    After changing that, I also got a 'TemplateException' on the same line of code for this.container.BackToForumsButton1, stating: A required control was not found in the template for "".  The control must be assignable form type "System.Web.UI.Control" and must have ID "backToForumsButton1".

    Moving on to CustomSingleThread, I get a NullReferenceException on this line:

    IPost

     

    currentThread = this.manager.GetPost(this.selectedThreadID);

     

    this.manager is equal to null. I'm actually a bit more confused about that one.  I upgraded to SP1, and am not using an external templates for the forums, so I'm nto sure what's going on there.

    In any case, thanks for point me in the right direction.  If you have a second to look into any of the above items, that would be great, but I'll certainly make an effort myself as well.

    Many thanks,
    Kevin.



  9. Kevin
    Kevin avatar
    42 posts
    Registered:
    15 Mar 2005
    23 Apr 2009
    Link to this post
    Just an update that the controls actually seem to work when viewing the pages on the client side ... it's just in 'design mode' (when editing the pages in the admin console) that I get the exceptions.  I can just skip over the errors when running in VS, but I don't know what would happen in a production environment where I can't just continue execution ... my guess is I'd always be redirected to an error page?
  10. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    24 Apr 2009
    Link to this post
    Hello Kevin,

    I have fixed the issues. The problems were in design mode only. When all items are set there will be no problems.

    For the issue with the BackToForumsButton1 in the CustomSingleThread - please check if the template located at [~your site]/Sitefinity/ControlTemplates/Forums/SingleForum.ascx - the button must exists and must be LinkButton:
    <asp:LinkButton ID="backToForumsButton1" runat="server" Text="<%$Resources:BackToAllForums %>"></asp:LinkButton> 
    This control is required and if you remove it, the TemplateException is thrown.

    You can use the  <customErrors element in the web.config to configure the page to which you could be redirected when an exception is thrown.

    I hope this will fix the problems.

    Greetings,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
Register for webinar
10 posts, 0 answered