SEO Friendly Urls in Sitecore -Remove spaces in Url (2)

by Aboo Bolaky 2. December 2008 11:03

This post is merely a follow up on my previous post : SEO Friendly Urls in Sitecore -Remove spaces in Url .

Even if you use the encodeNameReplacements settings in your web.config, this may well not be enough to get you going with clean urls. Although it will allow you to access an item by replacing the spaces with a dash (.i.e. if you chose to replace a space with a dash in the encodeNameReplacements element) in the url, the links that are rendered on the page (either by doing sc:link in xslt or the usual .net code) will still contain "%20" characters.

Now, this is the bit where I "kind of" messed up. In Sitecore V6 , we have the concept of LinkManager in the web.config. By default, the EncodeNames property is set to true. This is correct and you SHOUD NOT CHANGE IT. If the EncodeNames property is set to false, you will end up having "%20" characters in your hyperlinks.

The big question for me is when and why did I change the EncodeNames to false? I don't know.. Maybe I thought, at some point in time, that toggling the key to a value of false would solve some other problem that I was experiencing?

Anyway, had I not changed EncodeNames to false , I would have never the known the actual meaning and implications of EncodeNames. We learn from our mistakes... Cool

While we're here, you can remove the language code in the urls (http://hostname/en/node1/child.aspx) by changing the key languageEmbedding to "never". In that case, you will end with a url that looks like http://hostname/node1/child.aspx.

Back to Sitecore now..


.Net | Applications | Sitecore | Tips & Tricks

The WebUtil Class in Sitecore

by aboo bolaky 30. November 2008 06:36

For those Sitecore lovers..

When you code against Sitecore, whether against renderings or sublayouts, I'd suggest you have a look at the very useful methods defined in Sitecore.Web.WebUtil Class. Those methods will help save you some time and prevent you from re-inventing the wheel. Some methods worth mentioning are :-

string AddQueryString(string url, params string[] parameters)
string AddQueryString(string url, bool xhtml, params string[] parameters)
string ExecuteWebPage(string url)
string ExtractFilePath(string url)
string ExtractUrlParm(string name, string url)
Placeholder FindPlaceholder(string key, Control root)
HtmlAnchor GetAnchor(Item itm, string linkField)
Control GetErrorControl(string error, string details)
Control GetFormControl(Page page)
string GetFormValue(string fieldName)
string GetFullUrl(string url, string serverUrl)
string GetHostIPAddress()
string GetHostName()
string GetQueryString()
string GetQueryStringOrCookie(string key, string defaultValue)
void RedirectToErrorPage(string text)
string RemoveQueryString(string url)
void ReloadPage()
string ReplaceUrlParameter(string url, string replace, string withtext, bool append)

Alternatively, you can have a peek at all the methods in the screen grab below [Click on the image for a better view..]


.Net | Applications | Sitecore | Tips & Tricks

SEO Friendly Urls in Sitecore -Remove spaces in Url

by aboo bolaky 29. November 2008 09:50

Aliases in Sitecore

Sitecore has the concept of "Aliases", whereby each item can accessed using a specific name (rather than the default path). Aliases are turned on by default. To turn them off, you can flip the web.config settings name AliasesActive to false (But who would want to do that???? Sealed)

Space Characters in Sitecore

When you create an item in Sitecore, you free to choose the naming of your item (provided it succesfully validates against some key rules .e.g Item name cannot contain :,?.. otherwise, you will end up with a "Item xxx is not a valid name"). Most of the time, you will want to put spaces in the item name. Let's take an example:

If an item (at the root level) has an item name of "John Doe", the url of the actual page should theoretically be http://hostname/John%20Doe .

Of course, you can get rid of this spacing issue by specifying an Alias of John-Doe on the item itself. But imaging you having hundreds of items with spaces !!!..

The encodeNameReplacements element in the Web.config

This encodeNameReplacements settings allow you to globally replace any unwanted character in your url to a character of your choice. So, rather than creating an alias for each item (without spaces), we can add the following new setting.

	<replace mode="on" find="&" replaceWith=",-a-,"/> 
	<replace mode="on" find="?" replaceWith=",-q-,"/>
	<replace mode="on" find=" " replaceWith="-" />

Job Done ! Cool



.Net | Applications | Sitecore | Tips & Tricks

Method Overloading in WCF

by aboo bolaky 24. November 2008 07:32

In WSDL-based operations, method overloading is hard to achieve. It's not as easy as it would seem with C++ or even C#, where an interface could be defined as

public interface IHelloWorld
	void Add(int num1 ,int num2);
	void Add(string s1, string s2);

When you implement this interface in your class, the code (if it's well written Sealed) will compile just fine. The moment you update your service reference, it all goes crazy. The Error Message is "The Request failed with the error message : Cannot have two operations in the same contract with the same name".

The resolution is to add the Name attribute to the OperationContract on each method defined in the interface.

public interface IHelloWorld
	[OperationContract(Name="AddNumber") ]
	void Add(int num1 ,int num2);
	void Add(string s1, string s2);

When proxy is generated on the client, the operations now have aliased names.  NICE !!

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "")]
public interface IHelloWorld 
	void AddNumber(int num1, int num2);

	void ConcatenateStrings(string s1, string s2);



.Net | WCF | Tips & Tricks

Using Microsoft Search Server Express 2008 Web Services

by Aboo Bolaky 21. November 2008 09:39

WebService Location

The Url for the webservice is usually in the form of http://servername:portnumber/_vti_bin/Search.asmx

PS: Make sure you enter the actual server name instead of the IP address. Otherwise, you might end up with an ArgumentNull Exception when trying to invoke the QueryEx webmethod.

PS: Always call the Status Webmethod (returns "ONLINE" if the search service is up and running) prior to actually querying MSSE 2008.

Crawling Content

To be on the safe side, always add a crawl rule with a path of*  and a crawl configuration of "Crawl complex URLs (URLs that contain a question mark (?))". Otherwise, the crawler will ignore pages that contain querystrings. Big thanks go to David for pointing this out to me.

Search Scopes

You would use search scopes where you may want to query within "specific parts of a collection". This is analogous to collection/subcollections in Google Mini. The gotcha here is that if you specify a search scope in your query (either SQL-Like query or keyword based query), you might end up with an "Scope in your query does not exist. " error message. This is not the end of the world. The problem here is that you search scope is supposed to be SHARED across the Shared Services Provider. Now, how do we create a shared scope? It's kinda hard to figure this one out. When you normally create a search scope, there is no option to choose whether or not the scope can be shared.

Creating a Shared Scope in MSSE 2008.

The only way I found to create a shared Scope is to create a search scope using the normal approach (Scopes for this search Server ->New Scope). Once you return to the View Scopes page, notice that there is no Create Shared Scope on the drop down list for the target search scope. The current url looks like : http://servername/_layouts/viewscopes.aspx?mode=site. Substitute the mode=site querystring key pair with mode=ssp and hit Enter. You are now in Shared Services Provider mode. When you view the items in the drop down for your search scope, you now have an option to "Make Copy as Shared". Once this is clicked, a Shared Scope with a name of "Copy of .." is created. Of course, do not forget to add rules to your search scope.

You can then manually update your new search scope on the Search Administration Home Page. Once the update is complete, you can use your name of shared scope in your Query XML. One thing i noticed is that there is no place where I can update the name of the Search Scope. weird.. If you know how to do this, please drop me a few lines. i'd be interested to know :P

Word Stemming

This is disabled by default. To enable stemming, you need to perform a basic search on the Search Center Site. On the result page, go to Site Settings -> Edit Page. Edit the webpart Search Core Results (Modify shared webpart). Expand Results Query Options. Make sure the checkbox Enable Search Term Stemming is checked. Voila !!

I hope this is enough to get you going with Microsoft Search Server Express 2008. Cool



.Net | Applications | Tips & Tricks

Creating a collapsible HTML List using JQuery

by Aboo Bolaky 17. November 2008 17:19

Yesterday, I came across this really nice article by Jeroen Coumans that explains how to create a collapsible HTML list using JQuery. The reasons why I like his solution are:

1. It's simple and easy to understand. It takes only a couple of lines to write the JQuery code.

2. It allows you to add the "active" CSS class to the selected item in the list.

3. Most importantly, it allows you to have a clickable parent item (where the link to the parent item doesn't just point to a #; it can refer to other pages on your site) 

You can have a look at the article here



.Net | Asp.Net | Tips & Tricks

Recursively delete _svn folders

by Aboo Bolaky 4. October 2008 09:37

Basically, there are several ways to approach this problem.

1. Ditch Windows Development and use any flavour of Unix. The commands on the Unix shells are far more functional (and better...i think) and you'd be amazed as to what you can do. Drawback here is that you need to choose your favourite shell and learn the commands inside out..Not so easy Frown. Well, the good news here is that if ever you need to recursively delete _svn folders, you only need to do a simple search on google and you'll get your answer within a few clicks. Or, better still, drop Colin a few lines. I'm sure he will be able to help you out Laughing

2. Have a peek at Eber Irigoyen Blog. He has provided us with a simple one-liner command that runs off the command line.  [Nice one dude...]

for /f "usebackq" %d in (`"dir *_svn /ad/b/s"`) do rd /s/q "%d"

3. Simple enough. This involves using Tortoise SVN Client to export your project somewhere else. By doing so, all svn folders will be subsequently deleted in the destination folder.

4. Now this is the techie bit. If you think that all the solutions above are too trivial, you may want to have a look at the FreeToDev MSBuild Tasks Suite available on Codeplex . This suite comprises of over 170 tasks including the .NET framework, TFS , IIS 7 and many more. Documentation is given for each and every task. HINT : use the FDTFolder task to recursively delete _svn folders.

5. If none of these work for you, may I suggest grabbing yourself a drink and flex your fingers for some mouse and keyboard delete action.


Tips & Tricks

Annoying Large Icons in the Windows Vista Deskop - Decrease Icon Size

by Aboo Bolaky 4. October 2008 09:26

If you are tired with the big fat desktop icons that come along with Windows Vista, there's something to cheer you up. To decrease the size of the icons, simple click anywhere on your desktop.While pressing the CTRL key, use your wheel mouse to increase/decrease the size of the icons. The sweet thing here is that the sizes are persisted across restarts. Too bad for you if you do not have a wheel mouse..maybe it's about time to get one? Money mouth


OS | The AByss | Tips & Tricks

Tag cloud

Flash Player 9 required.

About Me

I wish I could write something here..
//TODO: ElaborateMe