September 2007 - Posts

Google Ranking effected by Response.Redirect

It seems that search engines, like Google, frown on the 302 Redirect due to hijacking and that is the method that is the ASP.NET response.redirect uses.

That would also explain why our sites main page has yet to be issued a PR rating by google. We were doing a response.redirect from the default page to a page in our document library. In fact I have a posting earlier in the blog explaining how to do it - sorry.

The correct way to do a redirect for a permanent type of page like a root default page going to page library is:

  Response.Status = "301 Moved Permanently";
  Response.AddHeader("Location","http://sharepointsearch.com/pages/default.aspx");
  Response.End();

Now lets see how long it takes to get our pr rating.

 

UPDATE: 10/18

Our PR remains at 0/10. So trying something new.

 void Page_Init()
    {
        Server.Transfer("/pages/default.aspx");
 }

This will allow the http://sharepointsearch.com   to display the contents at /pages/default.aspx without doing any form of redirect. This kind of transfer will really only work well with a page that doesn't do any post backs and mostly links out, which our main page.

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks
Posted by notorioustech | with no comments

Adding refer (digg, technorati ..) links to Community Server blogs

I needed a way to add the standard community referring links to blog posts in Community Server. I was surprised by how easy it actually was. So if you are using CommunityServer.org 2007 and want to do the same then follow these instructions.

1. create a c# project in visual studio and add this code below to a new class in the project. Fix the namespace of course.

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;

namespace SPWorks.CS.Integration
{
    class SPWReferIt : ICSModule
    {
        private bool _syndicate = true;
        private bool _web = true;
        private DateTime _dateFilter = DateTime.MinValue;
        private string links = "";
        public void Init(CSApplication csa, XmlNode node)
        {
            csa.PreRenderPost += new CSPostEventHandler(csa_PreRenderPost);
            links = node.Attributes.GetNamedItem("ReferLinks").Value;
             if (links == null) links = "";
             links = Globals.UrlDecode(links);
        }
        private void csa_PreRenderPost(IContent content, CSPostEventArgs e)
        {
            if (e.Target == PostTarget.Web)
            {
                if (!_web)
                    return;
            }
            else if (e.Target == PostTarget.Syndication)
            {
                if (!_syndicate)
                    return;
            }
            if (e.ApplicationType == ApplicationType.Weblog)
            {
                WeblogPost wp = content as WeblogPost;
                bool includePost = (e.Target == PostTarget.Web || wp.PostDate >= _dateFilter);
                if (wp != null && wp.PostLevel == 1 && includePost)
                {
                    string link = Globals.FullPath(BlogUrls.Instance().Post(wp));
                    string title = wp.Subject;
                    if (title.Length > 150) title = title.Substring(0, 149);
                    string[] tags = wp.Categories;
                    string tagsstr = "";
                    if (tags != null)
                    {
                        for (int i = 0; i < tags.Length; i++)
                        {
                            if (tagsstr != "") tagsstr += " ";
                            tagsstr += tags[i];

                        }
                    }
                    string tagsEncode = Globals.UrlEncode(tagsstr);
                    string titleUrlEncode = Globals.UrlEncode(wp.Subject);
                    string linkEncode = Globals.UrlEncode(link);
                    string linksstr = links;
                    if (linksstr != "")
                    {
                        linksstr = "\n" + linksstr.Replace("[TAGS_ENCODED]", tagsEncode).Replace("[URL_ENCODED]", linkEncode).Replace("[TITLE_ENCODED]", titleUrlEncode).Replace("[TAGS]", tagsstr ).Replace("[URL]", link).Replace("[TITLE]", title);
                    }

                    wp.FormattedBody += linksstr; 
                                 }
            }
        }

    }
}

 

2. Add references to the CommunityServer blogs and components dlls to your project

3. Compile and put your dll in the bin directory of the CommunityServer web site.

4. Open the CommuntyServer.config file and make new entry for your module like so:

<add name = "SPWReferItModule" type = "SPWorks.CS.Integration.SPWReferIt,SPWorks.CS.Integration" ReferLinks="" />

5. In the step above the ReferLinks attribute is where you will put your html template for creating the links. In SHAREPOINTSearch's case we chose the follow URLs:

<a href="http://del.icio.us/post?url=[URL_ENCODED]&tags=[TAGS_ENCODED]&title=[TITLE_ENCODED]" mce_href="http://del.icio.us/post?url=[URL_ENCODED]&tags=[TAGS_ENCODED]&title=[TITLE_ENCODED]">Del.icio.us</a> | <a href="http://digg.com/submit?phase=2&url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://digg.com/submit?phase=2&url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">Digg It</a> | <a href="http://technorati.com/cosmos/search.html?url=[URL_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://technorati.com/cosmos/search.html?url=[URL_ENCODED]&tags=[TAGS_ENCODED]">Technorati</a> | <a href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=[URL_ENCODED]&Title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=[URL_ENCODED]&Title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">Blinklist</a> | <a href="http://furl.net/storeIt.jsp?t=[TITLE_ENCODED]&u=[URL_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://furl.net/storeIt.jsp?t=[TITLE_ENCODED]&u=[URL_ENCODED]&tags=[TAGS_ENCODED]">Furl</a> | <a href="http://reddit.com/submit?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://reddit.com/submit?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">reddit</a> | <a href="http://www.dotnetkicks.com/submit/?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://www.dotnetkicks.com/submit/?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">DotNetKicks</a>

 NOTE: the replacement holders: [TITLE_ENCODE] [URL_ENCODE] [ TAGS_ENCODE] . these are pretty self explanatory and use these to add your own refer it links to the template. When you have the template ready. Then use http://www.albionresearch.com/misc/urlencode.php to URLEncode the whole string and paste it into the ReferLinks attribute. 

THAT's it. It took me exactly 35 minutes to write and should take you 10 to use.

You can try it out on this blog post itself. See:  

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks