如何从HttpContext.Current获取HttpContextBase

・1 分钟阅读

为了实现服务器端Google Analytics跟踪到请求监视的API,我们决定尝试一下这个库:

https://github.com/maartenba/GoogleAnalyticsTracker

为了让下面的例子在Global.asax文件中工作


Tracker tracker = new Tracker("UA-XXXXXX-XX","www.example.org");
tracker.TrackPageView(HttpContext,"My API - Create");

我需要以某种方式将HttpContext.Current转换为抽象类HttpContextBase 。

结果就这样简单:

new HttpContextWrapper(HttpContext.Current)

所以这个例子变成了:


Tracker tracker = new Tracker("UA-XXXXXX-XX","www.example.org");
tracker.TrackPageView(new HttpContextWrapper(HttpContext.Current),"My API - Create");
Jiaoyang75 profile image