GetVirtualPath() in a LoadedPage event

Vote:
 

Hi all!

 

I have not developed for EPiServer before and am running into a problem which hopefully is something silly that I can laugh about all weekend long.

Here's an excerpt of my class:

namespace MyNamespace
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]

    public class MyClass : IInitializableModule
    {
        private bool _eventsAttached = false;

        public void Initialize(InitializationEngine context)
        {
            if (_eventsAttached) return;

            DataFactory.Instance.LoadedPage += LoadedPageHandler;

            _eventsAttached = true;

        }

        private void LoadedPageHandler(object sender, PageEventArgs pageEventArgs)
        {
            var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
            using (var file = new System.IO.StreamWriter(@"C:\ESDebug\LoadedPage.txt", true))
            {
                file.WriteLine("Event Loaded page: " + urlResolver.GetVirtualPath(pageEventArgs.Page.ContentLink, pageEventArgs.Page.LanguageBranch));
            }
        }

    }
}

Uninitialize(), Preload(), etc are removed to keep post size down.

The file output is just there for debugging (was added late and is not the problem itself...)

I have tried using both pageEventArgs.Page.ContentLink, pageEventArgs.ContentLink, pageEventArgs.PageLink, all to no avail. Same result regardless. Attaching with VS gives the same result as well.

 

GetVirtualPath returns null.

 

If I put the same 5 lines into a controller it gives me the path.

 

I'm using the LoadedPage event only as a test, I intend to use other events but picked that one because it triggers just by browsing in.

 

Can someone tell me what I'm doing wrong or if you want some more data?

 

Thanx

 

// Stefan

#75939
Oct 11, 2013 14:46
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.