Guest User

Untitled

a guest
Jan 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  2. <sitecore>
  3. <customHandlers>
  4. <handler trigger="sitemap.xml" handler="sitemap.ashx" />
  5. </customHandlers>
  6. </sitecore>
  7. </configuration>
  8.  
  9. <add path="sitemap.ashx" verb="*" type="MySite.CustomSitecore.Handlers.SitemapHandler,MySite" name="SitemapXml" />
  10.  
  11. namespace MySite.CustomSitecore.Handlers
  12. {
  13. public class SitemapHandler : IHttpHandler
  14. {
  15. public bool IsReusable
  16. {
  17. get
  18. {
  19. throw new NotImplementedException();
  20. }
  21. }
  22.  
  23. public void ProcessRequest(HttpContext context)
  24. {
  25. try
  26. {
  27. var curSite = Sitecore.Context.Site;
  28. var m_Sites = SitemapManagerConfiguration.GetSites();
  29. foreach (DictionaryEntry site in m_Sites)
  30. {
  31. if (site.Key.ToString().Equals(curSite.Name))
  32. {
  33. var filepath = site.Value;
  34. HttpContext.Current.Response.Redirect("/" + filepath, false);
  35. return;
  36. }
  37. }
  38. return;
  39. }
  40. catch (Exception ex)
  41. {
  42. Log.Info("Error in SitemapHandler: " + ex, this);
  43. }
  44. }
  45. }
  46. }
  47.  
  48. HttpContext.Current.Response.StatusCode = 200;
  49. HttpContext.Current.Response.ContentType = "text/xml";
  50. HttpContext.Current.Response.AddHeader("Location", "/" + filepath);
  51. HttpContext.Current.Response.End();
  52. return;
Add Comment
Please, Sign In to add comment