AI OnAI Off
You are correct.
var resolver = ServiceLocator.Current.GetInstance<SiteDefinitionResolver>();
var site = resolver.GetDefinitionForContent(page.ContentLink);
var siteId = site.Id;
Hello Frank
It depends on your exact requirements but you should be able to use the ServiceLocator (or constructor injection) to get an instance of SiteDefinitionRepository then use the Get method with the current HttpContext to get the current site defintion which includes the Id. If you want to write tests around this you can mock the SiteDefinitionRepository implementation.
http://world.episerver.com/documentation/Class-library/?documentId=cms/9/780BF6D8
David
I have a question about getting the site id from a class library in episerver. I figure it's simple, but with the keywords episerver, site and id I came up with a sea of irrelevant results.
I am using episerver 9. The only way I have found so far involves using the SiteDefinitionResolver class and the current page. I need access to the site id in a class library. Is there some other way to get the current site id? I guess I could pass it in from the UI, but that seems a bit ugly as we have put wrappers around the episerver wrappers to remove as many dependencies to episerver from our UI and service layer as possible.
Thanks