Try our conversational search powered by Generative AI!

SiteDefinition.Current.SiteUrl returns null in AfterInstall()


We are trying to acces `SiteDefinition.Current` at the time of `AfterInstall`. What we need is `SiteUrl` and `Id` but it seems that at the time of this event they are not available.

How can we postpone the calling of `AfterInstall` or otherwise, could we attach an event listener in `AfterInstall` that can later in the pipeline provide us the data?


From what I can see in the documentation and from here (enumerating the order of the execution of dependencies), decorating the class like the following should have EPiServer.Web initialized, and  by extent, SiteDefinition.Current.

public class ModulePackageInitializer : PackageInitializer

Decorated the class like bellow with no results.

public class ModulePackageInitializer : PackageInitializer
Aug 07, 2017 15:27

Not sure, it will solve your problem documentation says you should add dependency on  PackagingInitialization (Derived class should be marked with ModuleDependencyAttribute with dependency on PackagingInitialization.))

Aug 07, 2017 23:27

Hi Tahir,

We have tried that as well. Same result. unfortunately.

Aug 08, 2017 9:38

Just another pointer, Are you aware of "TerminateInitializationException"? 

Check this link as well

Aug 08, 2017 10:05

No I was not aware. How can it be used?

Like this?

if (SiteDefinition.Current.SiteUrl == null)
            throw new TerminateInitializationException();

Aug 08, 2017 10:47

Effectively yes. See the URL that I pasted in last post. He is doing the same thing as you are...

Aug 08, 2017 12:05

I have seen it, but am not aware of the methods he is calling>

 var section = EPiServerFrameworkSection.Instance; 
         var configSiteId = SiteIdFromConfig(section); // Get info from config file / 

         var actualSiteId = SiteIdFromRequest();   

"InitializeFromConfig", "SiteIdFromConfig" and "SiteIdFromRequest"

Edited, Aug 08, 2017 13:01
<p>Solved with this</p> <pre class="cs hljs" contenteditable="false"><span>var</span> siteDefinitionRepository = ServiceLocator.Current.GetInstance&lt;SiteDefinitionRepository&gt;(); <span>var</span> siteDefinitions = siteDefinitionRepository.List().ToList();</pre>
Aug 08, 2017 13:55

You should use the interface instead

var siteDefinitionRepository = ServiceLocator.Current.GetInstance<ISiteDefinitionRepository>();
var siteDefinitions = siteDefinitionRepository.List().ToList();
Oct 26, 2018 14:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.