Created
November 9, 2016 19:54
-
-
Save sshibani/90ff5c48ddb1f86ab84214347940b3b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PublicationResolver : IPublicationResolver | |
{ | |
private readonly DynamicMappingsRetriever _mappingsRetriever; | |
public PublicationResolver() | |
{ | |
_mappingsRetriever = new DynamicMappingsRetriever(); | |
} | |
public int ResolvePublicationId() | |
{ | |
return this.Resolve().PublicationId; | |
} | |
private int Resolve() | |
{ | |
var url = HttpContext.Current.Request.Url.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("publicationId not found"); | |
} | |
return mapping.PublicationId; | |
} | |
catch (Exception ex) | |
{ | |
throw new Exception("publicationId not found", ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment