Try our conversational search powered by Generative AI!

Get EPi page content from external project

Vote:
 

Hi,

I have a Visual Studio solution that looks like this:


Solution


- EPi web project
  - test1.aspx

- Web service web project
  - test2.aspx

- Class library project
  - class1.cs
    - GetChildPages(int parentId)

 

The web projects are released on different domains and they both use logic in the class library.

 

The method looks like this:
GetChildPages(int parentId)
{
    PageData pd = EPiServer.DataFactory.Instance.GetPage(new PageReference(parentId));
    //todo: loop pd children...
}


Calling GetChildPages(int parentId) in test1.aspx works fine.

Calling GetChildPages(int parentId) in test2.aspx results in this exception:
DataFactory.Instance = 'DataFactory.Instance' threw an exception of type 'System.TypeInitializationException'


My guess is that I get this error because test2.aspx is not located in a EPi web project (with all EPi settings etc).

How can I make it possible to call the class library method from test2.aspx (a normal Visual Studio web project)?

 

 

#79732
Jan 02, 2014 17:42
Vote:
 

You can take a deeper look at EPiServer.Global class (from which your Global.asax.cs is inherited in EPi web project). There is a pretty heavy initialization procedure. I would start with EPiServer.Global type constructor to understand further call chain.

You would also need to copy over few configuration files to properly initialize CMS context (part of the web.config file, episerver*.config, connectionStrings.config).

A good starting point would be: http://tedgustaf.com/sv/blogg/2010/8/unit-test-an-episerver-6-website-using-visual-studio-2010-and-mstest/

#79860
Jan 08, 2014 17:18
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.