代码之家  ›  专栏  ›  技术社区  ›  Paul Rowland

Web客户端软件工厂createnewattribute属性不在global.asax中工作

  •  0
  • Paul Rowland  · 技术社区  · 16 年前

    我们在代码隐藏页中使用以下代码

    [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]属性从全局页访问控制器?

    1 回复  |  直到 13 年前
        1
  •  0
  •   Paul Rowland    16 年前

    我不知道如何访问控制器,但是我可以通过下面的代码片段获得服务。

    [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);
        }
    }