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.
Okay, this one's a bit interesting.
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...
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?
Glad to hear it's a viable solution!
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.
José,
Thanks again for your help...you rule!
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.
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...
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
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)
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:
The link seems to work properly mysite.com/blogs/myblog.aspx however i receive this 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
Any ideas would be greatly appreciated
Thanks in Advance
Copyright© 2008 Telligent Systems Inc. All rights reserved CommunityServer.com • Telligent.com