2009-08-06 60 views
0

不工作,我們正在使用下面的代碼的代碼頁背後Web客戶端軟件工廠CreateNewAttribute財產在Global.asax中

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

和控制器類中的以下代碼

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

這個作品罰款一個正常的aspx頁面。

我想在我的應用程序中審計一個會話開始事件,並且我正在使用global.asax事件來執行此操作。

但是控制器在這裏沒有實例化

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

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

如何從使用[CreateNew]屬性的全局頁面訪問控制器?

回答

0

我沒有解決如何訪問控制器,但我可以通過以下代碼片段獲得服務。

[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); 
    } 
} 
相關問題