Ninject拦截器和asp.net网络表单

时间:2016-07-14 09:19:33

标签: c# asp.net webforms ninject

我在项目中使用ninject,一切顺利。但我想使用拦截模式在我的网页中记录一些请求。

我已经做了一些关于它的研究,我找到了一个asp.net MVC的解决方案,我尝试适应webforms,但它不适合我。我做的是......

创建一个继承自Ninject.Web.PageBase

的PageBase
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

让我的所有页面都继承自我的新PageBase

     public partial class PageBase : Ninject.Web.PageBase
       {
           // some code
       }

创建我的拦截器

public partial class Default : PageBase
{
}

并尝试配置内核来拦截我的PageBase ......但问题出在这里,因为我不知道如何配置它。

public class WebFormsInterceptor : SimpleInterceptor
    {
        readonly Stopwatch _stopwatch = new Stopwatch();

        protected override void BeforeInvoke(IInvocation invocation)
        {
            _stopwatch.Start();
        }

        protected override void AfterInvoke(IInvocation invocation)
        {
            _stopwatch.Stop();
            string message = string.Format("Execution of {0} took {1}.",
                invocation.Request.Method,
                _stopwatch.Elapsed);
            Log.Debug(message);
            _stopwatch.Reset();
        }
    }

0 个答案:

没有答案