views:

135

answers:

1

We are using the following code in a code behind page

[CreateNew]
public AdminController Controller { get; set; }

and the following code within the controller class

[ServiceDependency]
public IAdminService Adminervice { get; set; }

this works fine for a normal aspx page.

I would like to audit a Session starting event in my application and I'm using the global.asax events to do so.

However the controller has not been instantiated here

protected override void PrePageExecute(System.Web.UI.Page page)
{

    if (Controller == null)
    {
           // controller is null...
    }
}

How can I access the controller from the global page using the [CreateNew] attribute?

A: 

I didnt work out how to access the controller, but I could get the service with the following snippet of code.

[ServiceDependency]
public ICommonService CommonService { get; set; }

protected override void PrePageExecute(System.Web.UI.Page page)
{
    if (Session.IsNewSession)
    {
        if (CommonService == null)
        {
            WebClientApplication.BuildItemWithCurrentContext(this);
        }
        CommonService.AuditTrailLogin(true);
    }
}
Paul Rowland