Skip to content

Instantly share code, notes, and snippets.

@sshibani
Last active October 20, 2016 13:42
Show Gist options
  • Save sshibani/34a955a2bbb1f13dfda659ed1067d9ea to your computer and use it in GitHub Desktop.
Save sshibani/34a955a2bbb1f13dfda659ed1067d9ea to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Tridion.ContentDelivery.DynamicContent;
namespace SDlWeb8.Examples
{
public class PublicationMappingResolver
{
private readonly DynamicMappingsRetriever _mappingsRetriever;
public PublicationMappingResolver(ILogger logger)
{
_mappingsRetriever = new DynamicMappingsRetriever();
}
public IPublicationMapping Resolve(Uri uri)
{
var url = uri.GetLeftPart(UriPartial.Path);
int espaceIndex = url.IndexOf("%");
if (espaceIndex > 0)
{
url = url.Substring(0, espaceIndex);
}
try
{
var mapping = _mappingsRetriever.GetPublicationMapping(url);
if (mapping == null || (!mapping.Port.IsNullOrEmpty() && mapping.Port != uri.Port.ToString()))
{
throw new Exception(string.Format("Mapping not found for URL '{0}'", url));
}
return mapping;
}
catch (Exception ex)
{
throw new Exception(string.Format("Mapping not found for URL '{0}'", url));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment