首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServiceStack Profiler NullReferenceException

ServiceStack Profiler NullReferenceException
EN

Stack Overflow用户
提问于 2014-04-03 15:34:55
回答 1查看 584关注 0票数 0

我认为我正确地设置了ServiceStack的分析器,但也许我没有。我只是想把基本的东西准备好。

我至今所做的一切

到目前为止,我所采取的安装分析的唯一步骤是在Global.asax.cs中。

代码语言:javascript
复制
   private void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Request.IsLocal)
        {
            Profiler.Start();
        }
    }

    private void Application_EndRequest(object sender, EventArgs e)
    {
        Profiler.Stop();
    }

在我的_SiteLayout.cshtml页面中,在呈现任何其他javascript文件之前,我尝试呈现如下:

代码语言:javascript
复制
<body>
<!-- ... -->

@Html.Raw(HttpUtility.HtmlDecode(Profiler.RenderIncludes().ToString()))

<!-- ...other scripts... -->
</body>

我收到的错误:

NullReferenceException:对象引用没有设置为对象的实例。 ServiceStack.MiniProfiler.UI.MiniProfilerHandler.RenderIncludes(Profiler分析器、可空1 position, Nullable1 showTrivial、可空1 showTimeWithChildren, Nullable1 maxTracesToShow、布尔xhtml、可空1 showControls, String path) +293 ServiceStack.MiniProfiler.Profiler.RenderIncludes(Nullable1位置、可空1 showTrivial, Nullable1 showTimeWithChildren、可空1 maxTracesToShow, Boolean xhtml, Nullable1 showControls) +99 ……

考虑到我正在尝试完成基本任务,我不确定此时什么可能是空的。在启动分析器之前是否需要进行某种额外的设置?会不会是路由问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-22 21:25:13

在这种情况下,解决方案似乎是只使用标准的MiniProfiler库,而不是ServiceStack中包含的库。

初始设置

在Nuget包安装程序中,我运行了:

代码语言:javascript
复制
Install-Package MiniProfiler
Install-Package MiniProfiler.MVC4

我以以下方式修改了global.asax

代码语言:javascript
复制
private void Application_BeginRequest(object sender, EventArgs e)
{
        MiniProfiler.Start();
}

private void Application_AuthenticateRequest(object sender, EventArgs e)
{
     //stops the profiler if the user isn't on the tech team
    var currentUser = ClaimsPrincipal.Current.Identity as ClaimsIdentity;
    if (!Request.IsLocal && !currentUser.GetGlobalRoles().Contains(Constant.Roles.TechTeam))
    {
        MiniProfiler.Stop(discardResults:true);
    }
}

private void Application_EndRequest(object sender, EventArgs e)
{
    MiniProfiler.Stop();
}

然后,在我的Layout.cshtml文件中,在body标记结束之前,我放置了:

代码语言:javascript
复制
    @MiniProfiler.RenderIncludes()    

    </body>
</html>

分析DB连接

在返回我的OrmLiteConnectionFactory的代码部分,我使用以下代码:

代码语言:javascript
复制
    private OrmLiteConnectionFactory claimFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString(), true, SqlServerDialect.Provider)
     {
         ConnectionFilter = x => new ProfiledDbConnection(x as System.Data.SqlClient.SqlConnection, MiniProfiler.Current)
     };

这似乎可以很好地分析SQL和连接。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22842414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档