Display 'View My Blog' link in Upper Navigation: How To?

rated by 0 users
This post has 8 Replies | 2 Followers

Top 150 Contributor
Posts 151
Points 2,495
CFAITH Posted: Wed, Jan 24 2007 5:23 PM

First of all, I would like to thank all of the helpful people here in the CS forums...I am fairly new to CS, and I have felt very welcomed into the community! This helpfulness is one of the reasons...even though we paid for a commercial version...that we proudly display the "Powered by Community Server" graphic on our site! (http://blog.cfaith.com)

Anyway, down to the nitty gritty. I am very familiar with adding navigation buttons to SiteUrls.config. But I don't simply want to add a button with a hard-coded link; I now want to add a button that says "View my Blog." This button would take the logged in user to his/her blog (/blogs/{username}). I would obviously set the permissions so that it would only be viewable to registered users.

Now, I have no idea how/if variables can be used in the SiteUrls.config file....

So, my question is: does anybody know how to add a link to SiteUrls.config that can grab the name of the logged in user?

Please let me know if this question doesn't make sense, or if you need clarification. As always, thanks for taking the time to help me out.
 

--Bisnut
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers

Okay, this one's a bit interesting. Smile

Since SiteUrls has no idea who's logged in, and I'm guessing you'd like the least messy approach. Here's what I think:

Add a new <link> to the <navigation> section in SiteUrls.config. You'll need to pick a name, resourceName, and roles. Something like this:

<link name="myblog" resourceUrl="myblog" resourceName="myblog" roles="Registered Users" />

Then, still in SiteUrls.config, I would add a <url> to the <urls> section with a matching name. Something like this:

<url name="myblog" location="common" path="myblog.aspx" />

Finally, I'd create this new file, myblog.aspx, and put it in the correct location (in the root, since common = "/"). This file (attached) will be a redirect to a blog whose appkey equals the current user's username. The contents of the attached file:

<%@ Import Namespace="CommunityServer.Components" %>
<%@ Import Namespace="CommunityServer.Blogs.Components" %>
<script language="cs" runat="server">
    public void Page_Load()
    {
        Response.Redirect(BlogUrls.Instance().HomePage(CSContext.Current.User.Username));
    }
</script>

This solution assumes that every user who sees the link has a blog and the appkey of the blog equals the username. While it's not uber-elegant, you're only changing siteurls and adding a file.

Hope that helps.

One is glad to be of service...

Jose Lema

  • | Post Points: 35
Top 150 Contributor
Posts 151
Points 2,495
CFAITH replied on Wed, Jan 24 2007 7:55 PM

Awesome...that works perfectly. We have blogs auto-created, and users can't change the appkey of the blog, so this is a perfect solution.

I'd like to do this exact same thing for their photo gallery; how might that work? I would assume it's a very minor tweak to the same script?

--Bisnut
  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Wed, Jan 24 2007 8:14 PM

Glad to hear it's a viable solution! Smile

In order to get it working for the Photo Gallery, you need to change the 2nd Import to "CommunityServer.Galleries.Components" and change the Redirect to use GalleryUrls.Instance().ViewGallery(...)

While I didn't test it, it should work. Wink

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Top 150 Contributor
Posts 151
Points 2,495
CFAITH replied on Wed, Jan 24 2007 9:57 PM

José,

Thanks again for your help...you rule!
 

--Bisnut
  • | Post Points: 5
Not Ranked
Posts 4
Points 65

Jose, your code works for general scenario.

If CSContext.Current.User.Username is different from the blog url name, how to get the blog url name? You know, blogger can change the blog url in his control panel.

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers

Hi SinaCode,

You should be able to pull the profile's weblog property and use that as the url. This assumes that their weblog url is indeed pointing to their blog on your cs site. While the initial setting of this property is now automatic in Community Server 2007, I don't believe updates are kept in synch. It would be up to the user to keep their blog url updated.

Hope that helps...

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Top 75 Contributor
Posts 319
Points 4,880
shakes replied on Sun, May 6 2007 2:32 AM

i am trying to do something like this only i want to have a user access their profile from the main menu....tried to do this...<link name="user" resourceUrl="user" resourceName="user" roles="SystemAdministrator" />...but you don't get your own profile that way...i was thinking i could work off the navigation in the top right...does that work through the sign in?...i noticed that if you navigate to your profile using the controls in the top right while in the regular site the resulting url is /members/myprofile.aspx....however if you are in the control pannel and do this the resulting url is.../user/Profile.aspx?UserID=2102...just seems odd to me...ultimately i would like to have a drop down menu with myBlog and myPhotos etc...like how cs 07 is or a sub navigation bar would be cool too...in any case any help would be greatly appreciated...im kind of new to cs so please be specific...

peace shakes

Carolina Pulse

  • | Post Points: 5
Top 75 Contributor
Posts 319
Points 4,880
shakes replied on Mon, May 7 2007 11:52 PM

 Wanted to try and get the myBlog link to work and i am running into some problems. here is what i did...(i realize i am repeating steps here)

Placed this code in the <navigation> section of siteurls.config: 

<link name="myblog" resourceUrl="myblog" resourceName="myblog" roles="SystemAdministrator" />

Placed this code in the weblogs section of siteurls.config: (code in bold)

<location name="weblogs" path="/blogs/" themeDir="blogs"   type="CommunityServer.Blogs.Components.BlogLocation, CommunityServer.Blogs" >
    <!-- Home Pages -->
    <url name="myblog" location="common" path="myblog.aspx" />
    <url name ="webloghome"  path="" pattern ="default.aspx" physicalPath="##themeDir##" vanity="{2}" page="postlist.aspx" />
    <url name = "weblogapplication"  path="##blogdirectory##default.aspx" pattern="##blogName##/default.aspx" physicalPath="##blogthemeDir##"  vanity="{2}?App=${{app}}" page="postlist.aspx" />

Note: i tried this with and without location="common" and got the same error. Also tried to place it outside <location> i which case the link does not work.

Placed this code in main navigation section of resources.xml:

<resource name="myblog">myBlog</resource>

I then created a myblog.aspx file with the following code and placed it in mysite.com/blogs:

<%@ Import Namespace="CommunityServer.Components" %>
<%@ Import Namespace="CommunityServer.Blogs.Components" %>
<script language="cs" runat="server">
    public void Page_Load()
    {
        Response.Redirect(BlogUrls.Instance().HomePage(CSContext.Current.User.Username));
    }
</script>

The link seems to work properly mysite.com/blogs/myblog.aspx however i receive this error: 

Server Error in '/cs' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type 'CommunityServer.Components.CSFormPage' from assembly 'CommunityServer.Components'.

Source Error:

Line 5:    
Line 6: <!-- Fixes the doPostBack bug which happens when the Form control is not part of the .aspx page -->
Line 7: <pages pageBaseType="CommunityServer.Components.CSFormPage, CommunityServer.Components"/>
Line 8:
Line 9: </system.web>


Source File: c:\websites\unseaw360\unseaw.com\cs\blogs\web.config    Line: 7


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

Any ideas would be greatly appreciated

Thanks in Advance  

peace shakes

Carolina Pulse

Page 1 of 1 (9 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com