Reducing the Number of Clicks to Attachments

As we've mentioned several times in this book, there are really two audiences for your CMS site: content contributors and content consumers. As a result, there are some cases where the site should operate differently depending on who's using the site. For example, let's suppose that you create a template that allows content contributors to upload attachments. Let's further suppose that the attachment is the only content on that page. In this case, all the attachment templates are summarized in some list on the site as well.

If we were subscribers, the only thing we would be interested in is the attachment. We don't want to have to click a link to get to a posting and then click the link to the attachment. Instead, we should be able to simply click the link to the posting and automatically be redirected to the attachment.

Conversely, if we were the author, we would be interested in getting to that posting if the site were in Edit mode (remember the rule: You must be able to navigate to where you want to affect content). So how do you resolve the needs of these two distinct audiences? Easy. Create an attachment redirect template.

OK, let's review the "rules" for this template:

  • When a user clicks a link to a posting containing just an attachment, they should be automatically redirected to the posting.

  • When the site is in Edit mode, authors should be able to click the link to the posting and actually get to the posting without being redirected.

Well, that seems simple enough. It is. In Listing 36-4 you can see the code that you'll need to put in the code-behind of the attachment template to make all this work.

Listing 36-4 The code for the redirect attachment template

[View full width]

 private void Page_Load(object sender, System.EventArgs e) {       this.BodyTitle.Text = "<b>" + CmsHttpContext.Current.Posting. DisplayName + "</b>";       // Call the redirect logic       HandleRedirect(); } private void HandleRedirect() {       // Set a reference to the current Web Author Context       WebAuthorContext currentWebAuthor = WebAuthorContext.Current;       // Check to see if the various conditions where we don't want to       // redirect exist.  If so, just stay on the posting.  If not, redirect       // to the attachment.       if ((currentWebAuthor.Mode != WebAuthorContextMode.AuthoringNew) &&             (currentWebAuthor.Mode != WebAuthorContextMode.AuthoringReedit) &&             (currentWebAuthor.Mode != WebAuthorContextMode.PresentationUnpublished) &&             (currentWebAuthor.Mode != WebAuthorContextMode.TemplatePreview))       {             string redirectUrl = ((AttachmentPlaceholder)CmsHttpContext. Current.Posting graphics/ccc.gif.Placeholders["WhitepaperAttachment"]).Url;       Response.Redirect(redirectUrl);       } } 

As you can see, the code for this improvement is pretty simple. However, techniques like this can really mean the difference between a good implementation of CMS and one that just didn't quite make it.



Microsoft Content Management Server 2002. A Complete Guide
Microsoft Content Management Server 2002: A Complete Guide
ISBN: 0321194446
EAN: 2147483647
Year: 2003
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net