Manipulating URLs in 5.3

Last week I found and extremely simple tool in the namespace ‘Sitecore.Text’: UrlString. This class allows me to manipulate URLs in an easy way. Very usefull when you want to extend an URL with a querystring paramater. For example:

UrlString googleUrl = new UrlString(“http://www.google.nl/search?hl=nl”);
googleUrl.Add(“q”, “your search text”);
//Returns http://www.google.nl/search?hl=nl&q=your%20search%20text
Response.Write(googleUrl.GetUrl());

Or even when you want to change the protocol:

UrlString dotSitecoreFeed = new UrlString(“http://sitecore.alexiasoft.nl/feed/”);
dotSitecoreFeed.Protocol = “feed”;
//Returns feed://sitecore.alexiasoft.nl/feed/
Response.Write(dotSitecoreFeed.GetUrl());

Have a nice day!

3 thoughts on “Manipulating URLs in 5.3”

  1. Hi, I would like to change the url, according to the client browser language:
    I added this to my layout as a test:

    But for some reason this does not work 100%, the redirection takes for ever – any advice? Thanks 🙂

  2. Hi, I’ll try again :-), I would like to change the url, according to the browser language:

    I added this to my layout as a test:

    Sitecore.Text.UrlString str = new Sitecore.Text.UrlString(Request.RawUrl);
    str.Add(“sc_lang”, “en”);
    Response.Redirect(str.ToString());

    But for some reason this does not work 100%, the redirection takes for ever – any advice? Thanks :-=

Comments are closed.