CS Dev Guide: Site Urls

One of complicated things for developers who don't know the structure of Community Server is working with site locations and urls because they can't handle everything when someone changes site urls (i.e. blogging at root).

These guys have missed an important part of Community Server APIs, CommunityServer.Components.SiteUrls.

To be able to use the functionality of this namespace you need to create an instance of SiteUrls by calling Instance() method of it then get several urls in Community Server.

There are two general kinds of urls: those which are being retrieved from a method and those which are being retrieved from properties.

Urls that are being retrieved from string properties are easy to use because they don't require any parameter. ControlPanel is one of them because its a constant url:

string CPUrl = SiteUrls.Instance().ControlPanel;

But some urls require parameters to generate appropriate content.  For instance when a user accepts his invitation and clicks on a link in invitation email he should be redirected to a page which has a dynamic content based on the ID of the invitation to show appropriate message to user.  In these cases you should use some static methods that return string value of url by getting some parameters.  Here I get the url of a page which shows a specific message for Community Server Access Denied exception:

string MessageUrl = SiteUrls.Instance()

    .Message(CSExceptionType.AccessDenied, CSContext.Current.Url);

Another instance of urls that require a method to be retrieved is for some external links.  You already know Community Server uses a page to redirect blog comment and Trackback urls to a original urls.  Redirect() method gets the string value of original url and gives back the string value of new url.

string NewUrl =

    SiteUrls.Instance().Redirect("http://www.nayyeri.net");

One of most important and common SiteUrls.Instance() static methods is Post().  This method returns the url of a post (in forums) by getting its PostID.

string CurrentPostUrl =

    SiteUrls.Instance().Post(CSContext.Current.PostID);

In addition to this global url provider, each application has its own url provider in Community Server which is as same as global urls and can be used similarly.  For example here I get the url of current blog's About page:

string AboutPageUrl =

    BlogUrls.Instance().About(CSContext.Current.ApplicationKey);

Enjoy urling ...

posted @ 2006-08-03 09:56  AlphaWu  阅读(263)  评论(0编辑  收藏  举报