LetsTalkCode.com
Programmers talking about code

Sitecore - Changing the Url not to match what is in the content tree

March 1, 2010 10:03 by JeremySharp

I’m new to Sitecore and I was working on a new installation. I ran into trouble trying to shorten my Sitecore generated URL’s. Once I was done I thought that wasn't so bad. But the path to get there was painful.

What I am solving for:
When Sitecore generates the url’s for our files it uses the exact hierarchy that is setup in the content tree(this is a good thing). But in our case, we have a lot of Products & Recipes. Because of this we have ‘extra’ folders in our content tree that should never be seen by our web user. I did two things that together gave me the result I was looking for. 

Based on our folder structure in our content tree, Sitecore was generating the following url’s:

Seems easy enough here is how I did it:

Step 1:
Create a custom linkManager method that inherits from the standard sitecore linkmanager class. This new class will show Sitecore how I want my web links constructed.  Essentially for our case we want to avoid a folder that is in our content tree. 

A. Find the following LinkManager entry in my web.Config file. You need to change the Type attribute of the Sitecore ‘add’ node. This Type attribute should point to a newly created class file.    ( /configuraiton/sitecore/linkManager in the web.config file )

   1: <linkManager defaultProvider="sitecore">
   2:   <providers>
   3:     <clear />
   4:     <add name="sitecore" type="Library.Links.CustomFileName, nameSpace.NameSpace" addAspxExtension="true" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="true" />
   5:   </providers>
   6: </linkManager>

B. Create a class (CustomFileName) file. This new custom class should inherit from: Sitecore.Links.LinkProvider. In addition it needs to match the web.Config entry above. The new class file will have a single override for the GetItemUrl method:

   1: //Override of Sitecore GetItemUrl
   2: public override string GetItemUrl(Sitecore.Data.Items.Item item, UrlOptions options)
   3: {
   4:     if (item != null)
   5:     {
   6:        string templateName = item.Template.Name.ToLower();
   7:        //Verify the template name is products. 
   8:        //That is our qualifier for if the url should be scrubbed.
   9:        if (templateName == "product") 
  10:        {
  11:           string link = "/products/" + item.DisplayName;
  12:           //AddAspxExtension is False by default
  13:           if (this.AddAspxExtension == true) link += ".aspx";
  14:           return link; 
  15:        }
  16:        //If in recipe section of site scrub url
  17:        if (templateName == "recipe")
  18:        {
  19:           //Url qualifies replace the old url with new one 
  20:           //http://domain/recipes/recipe_name.aspx
  21:           string link = "/recipes/" + item.DisplayName;
  22:           //False by default
  23:           if (this.AddAspxExtension == true) link += ".aspx";
  24:           return link;
  25:        }               
  26:     }
  27:     return base.GetItemUrl(item, options);
  28: }

Step 2:
Next, create an Item Resolver class this will show Sitecore how to reconstruct the Url to accurately point to an item in the content tree. Remember in step 1 you changed how the links shows up in the browser. But in step 2 we are going to intercept that request coming from the browser and tell Sitecore where the content item lives in the content tree. 

A. Lets go back to the web.config file add an entry directly above the HttpRequest.LayoutResolver <processor> in the httpRequestBegin node.

   1: <httpRequestBegin>
   2: <processor type="Link.ClassFile.CustomUrlResolver, XXX.NameSpace" />
   3: </httpRequestBegin>

B. In this newly created class file we are going to change reconstruct our path to accurately point to the content tree content item. The example below adds the folder we previously stripped out (in step 1).

   1: public void Process(HttpRequestArgs args1)
   2: {
   3:    if (Sitecore.Context.Item == null)
   4:    { //item not found
   5:  
   6:       //get name of requested item, without the path
   7:       // WebUtil.GetUrlName(0) doesn't seem to work here - maybe hasn't been instantiated yet?
   8:       // so we'll just split the URL on '/' and grab the last element in the array
   9:       char[] splitter = { '/' };
  10:       string[] reqitempath_ar = args1.LocalPath.Split(splitter);
  11:       string reqItemName = reqitempath_ar[reqitempath_ar.Length - 1];
  12:                   
  13:       //Check for product in query string
  14:       if(reqitempath_ar[1] == "products")
  15:       {
  16:          //get prod/brand code
  17:          int prodbrand = 0;
  18:          if (int.TryParse(reqItemName.Replace("-", ""), out prodbrand) == true)
  19:          {
  20:             //sitecore query find me the item where the display name = prod/brand
  21:             int product = reqItemName.IndexOf('-');
  22:             string prodCode = reqItemName.Substring(0, product);
  23:             string brandCode = reqItemName.Substring(product + 1);
  24:             
  25:             // Sitecore query for the content item
  26:             string productItemQuery = string.Format("/sitecore/content/Foodservice/Home/Products//*[@Product Code='{0}' and @Brand Code='{1}']", prodCode, brandCode);
  27:             Sitecore.Data.Items.Item productItem = Sitecore.Context.Database.SelectSingleItem(productItemQuery);
  28:             Sitecore.Context.Item = productItem;
  29:          }
  30:       }
  31:       //Check for recipes in query string            
  32:       if(reqitempath_ar[1] == "recipes")
  33:       {
  34:          // Sitecore query for the content item
  35:          
  36:          //@@name is case sensitive because the request is coming from the url (all lowercase) I have capitalized the first letter of every word.
  37:          // If there is an error make sure the ITEM NAME of the recipe is capatalized.
  38:          string reqItemNameCaps = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(reqItemName);
  39:          string recipeItemQuery = string.Format("/sitecore/content/Foodservice/Home/Recipes//*[@@Name='{0}']", reqItemNameCaps);
  40:          Sitecore.Data.Items.Item recipeItem = Sitecore.Context.Database.SelectSingleItem(recipeItemQuery);
  41:          Sitecore.Context.Item = recipeItem;       
  42:       }
  43:    }
  44: }

Conclusion – To shorten a url you need to create a custom link provider which is nothing more than an override. As well as an UrlResolver class to catch the request and point it to the content item in the content tree. Hope this helps you as much as it would have helped me :).

 Related Blogs:

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .NET | Sitecore
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Going to Austin Code Camp 5/30

May 21, 2009 08:01 by JeremySharp
U coming?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

NWA Code Camp 2009

April 25, 2009 13:47 by JeremySharp

NWAcodeCampAwesome event great showing by our locals! I truly enjoyed this event and I hope you did as well.

#NwaCodeCamp was the best local event I have been to in a long time. I saw a lot of Very good sessions. I think Jason Vogel & @JaySmith ran an amazing event.

I had the opportunity to present on Silverlight DeepZoom. I wanted to post my PPT for anyone who attended and wanted the links. If you have any questions related to the event or to my presentation post away, I’ll either answer them or get you an answer.  I'm going to work on a blog post to go into some detail on using the Jellyfish Framework.

Silverlight DeepZoom PowerPoint Link: SilverlightDeepZoom.zip (382.51 kb)

nwaKeyNote 

**Also someone asked me what I was using to ZOOM on m desktop. Here is a link to that as well, it’s not in my PowerPoint.

Thanks
Jeremy


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

NWA Code Camp 09

April 21, 2009 03:21 by JeremySharp

 

Join me at NWA Code Camp 2009 I have a session on “Silverlight DeepZoom applications with Jellyfish” (an open source library for DeepZoom). I will be presenting after lunch check out all the topics at the Agenda page. Still not sure if you want to make it? My session was inspired by @KENAZUMA talk at MIX this year. Cllick here to watch it. (DONT WORRY) my session will be different and just as informative.

Check out these random DeepZoom sites to get a better feel for the technology:

thanks,
Jeremy


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

MIX09 - Pics

March 19, 2009 08:43 by JeremySharp

Silverlight-BF IMG_3213 

GUandME IMG_3195

IMG_3211 IMG_3193


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Mix – Me and the GU

March 19, 2009 08:36 by JeremySharp

GUandME For starters, I’m a really big fan of the “GU”!! So even though I felt like a complete school girl... After what must have been hours of standing there I finally 'made the move'.  I approached the Gu he was very personable and took time to talk to me about what I did and for the record was suprisingly engaged.  I not only got to talk to him I got my picture taken... Do I have to give up my man card for that ?

HAAAAA.

I just thought I would share that experience.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: ,
Categories: .NET | Events | Mix09
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

Mix – What’s New in Silverlight 3

March 18, 2009 09:11 by JeremySharp

Joe Stegman – Group Program Manager

Glboal notes:

  • Agenda talking about the Core Runtime.
  • Business libraries, Tooling and other core concepts being presented in other sessions.
  • Improved XAP compression built into the tools. 10 to 30% reduction in XAP size. Blend Bits available today. IMG_0165

Meeting notes

  • GPU Acceleration – quick tour, several other talks on media
  • Perspective 3D – put 2D objects in 3D space.
  • Animation Easing – Add it into a “perspective plane” <PlaneProjecton x:name=”P3”  rotationY=”-30”> around media element </>
    • UI to UI binding !!
    • EasingFunction – smoothness of animations
    • exported to excel looks easier.
  • Effects and Pixel Shaders
    • Effects
      • impact visual behavior
      • sl3 supports drop shadow and blur
    • SL3 supports cusom effects
      • cusom effects are implemented as shaders
      • shaders typically authored using HLSL
        • compiled into byte code using a DX SDK utility
        • SL3 consumes the byte codes
      • shaders allow developers to modify each pixel on a UI element before the pixel is rendered
      • shader = a per-pixel function or operation
  • Pixel APIs
    • Dynamic bitmap generation
      • read/write pixels in a bitmap
    • render a visual tree (elements) to a bitmap
  • Scenarios
    • Dynamic image generations for ex RT graphs
    • Image editing and effects
    • clone visual
  • Raw Audio
    • similar to pixel API’s but for audio / video
    • Scenarios
      • dynamic sound generation
      • custom audio/video decoders

DEMO

  • Played video created multiple snapshots of video on a mouse click
  • Demoed DropShadow effect
  • Shaders and effects

ChessDemoLOCAL MESSAGING

  • Cross plug in SL communication
    • Multiple plugin on same page, different browser tabs, different browsers
  • Implementation
    • shared memory imp
    • exposed like named pipes
    • string based message
  • Scenarios
    • mixed HTML and SL architecture

DEMO

  • Bouncing balls across multiple browsers
  • Chess game (browsers playing each other) :)

UI framework Improvements

  • Merged resource dictionaries
  • basedOn Styles
  • Styles can be “cleared”
  • Muliti0select ListBox
  • Listening to “handled” routed events
  • new VSM “invalid” states
    • Support on TextBox, CheckBox, ComboBox, ListBOX, RadioButton
  • More details: (Karen Corby) Friday presentation

Other Improvements

  • SystemColors
  • Savefile dialog
  • Text Improvements
    • ClearType
    • caretBrush
    • flag to optimize for animating text
    • Glyphs Support for system font
  • Image Refinements

NEW SDK

  • DockPanel
  • expander
  • label
  • treeview
  • viewbox
  • wrappanel
  • child…
  • ….
  • ….. IMG_0171

Other BIG additions

  • In the business talk 
    • Navigation framework
    • data control
    • SEO
    • n-tier
    • … .

OutOFBrowser

  • SL runs out of the browser
  • built into the core Silverlight runtime
  • enabled per application
    • manifest update
  • user gesture to take OOB
    • right click
    • custom button in the app
  • new networking API’s
    • connected / Disconnected
  • Offline API’s
    • launch state, update API’s

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Mix – Silverlight applications in the business application

March 18, 2009 09:01 by JeremySharp

BradAbramsBrad Abrams – Silverlight 3 goodness.

Must haves

  • Professional Feel
  • Rich data query
    • using NorthWind DB
  • validating data updates
  • Authentication
  • Different views

Demo

  • took the default SL3 app and pulled data from northwinds db, Datagrid , paging / sorting and the like. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .NET | Events | Mix09
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Mix Agenda

March 16, 2009 10:03 by JeremySharp

MixOnline_L Here is my narrowed down list of sessions I would like to attend. There is a problem several of these double up. I hope to narrow it further to 2 sessions per hour then for the most part catch half and watch the missing half on the video once its live. All sessions will be posted live less than 24 hours. So if you see something you like and I didn't take good notes check out visitmix.com !! Also doing a new thing this year hitting the workshops I'm pumped about that.

  • What's New in Microsoft Silverlight 3 MIX09-T14F
  • High-Speed RIA Development with the Microsoft Silverlight Toolkit MIX09-T15F
  • Deep Dive into Microsoft Silverlight Graphics MIX09-T17F
  • Creating Media Content for Microsoft Silverlight Using Microsoft Expression Encoder MIX09-T19F
  • The Next Generation of Microsoft Virtual Earth MIX09-T34F
  • Microsoft Silverlight Session Placeholder MIX09-T45F
  • Building Accessible RIAs in Microsoft Silverlight MIX09-T65M
  • When Errors Happen: Debugging Microsoft Silverlight MIX09-T68M
  • Microsoft Silverlight Is Ready for Business MIX09-T69M
  • Creating Media Content for Microsoft Silverlight Using Microsoft Expression Encoder MIX09-T19F
  • Microsoft Silverlight Media End-to-End MIX09-T43F
  • Delivering Media with Microsoft Internet Information Services 7 (IIS) Media Services and Microsoft Silverlight MIX09-
  • The Best Video and Photography on the Web in Microsoft Silverlight MIX09-T60F
  • Optimizing Performance for Microsoft Expression Encoder MIX09-T70M
  • Delivering Ads to a Silverlight Media Player Application MIX09-T18F
  • Building Microsoft Silverlight Controls MIX09-T16F
  • Adding Microsoft Silverlight to Your Company's Skill Set MIX09-T29F
  • Building a Rich Social Network Application MIX09-T35F
  • Building Amazing Business Centric Applications with Microsoft Silverlight 3 MIX09-T40F
  • Building Data-Driven Applications with Microsoft Silverlight and Microsoft ASP.NET MIX09-T41F
  • Consuming Web Services in Microsoft Silverlight 3 MIX09-T42F
  • Microsoft Silverlight Media End-to-End MIX09-T43F
  • The Best Video and Photography on the Web in Microsoft Silverlight MIX09-T60F
  • Building Microsoft Silverlight Applications with Eclipse MIX09-T66M

Thanks,
Jeremy


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: .NET | Events | Mix09
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Starting the journey to the clouds, Microsoft's Cloud Computing Platform

October 19, 2008 08:41 by JeremySharp
cloud_computing

It’s no secret that PDC will be where Microsoft announces their Microsoft cloud computing platform. But if you are like me you have heard that term abused throughout the industry. News on Microsoft's cloud computing platform as a back end for Silverlight applications will be some of the things I hope to key on throughout PDC. I wont be making the trip myself but have plenty of friends that are going.

Here is an interesting note I found on Bill Reiss blog that breaks down the PDC agenda for us: (http://www.bluerosegames.com/SilverlightBrassTacks/post/PDC-should-be-renamed-CDC-for-Cloud-Developers-Conference.aspx)

There are a couple of more Silverlight sessions, now with a total of 13, but what really struck me is that the category with the most sessions is Cloud Services, with 33. Windows 7 has 22, which is still a lot, but 33 is just incredible.

Microsoft’s platform has a collection of unannounced services that I’m sure will all come to light during the PDC keynote. Shortly thereafter I have no doubt someone will have these all listed out very nicely(more to come)!! 

Here are some links of some of the services if your looking to understand how and where Red Dog, Zurich, BizTalk Services and SQL Server Data Services (SSDS) all fit together, David Chappell’s White paper on  “A short introduction to cloud platforms: An Enterprise-Oriented View.”.  Is worth a look he does not mention Zurich & SSDS by name but there are details to help fill in the holes.

For those of you NOT wanting to dig into the 13 pages Mary-Jo Foley from ZDNET.com provides the cliff notes to Chappell’s white paper. Another nice link and picture provided from Mike Kavis – “The future is in the clouds”.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5