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: }