我认为我正确地设置了ServiceStack的分析器,但也许我没有。我只是想把基本的东西准备好。
我至今所做的一切
到目前为止,我所采取的安装分析的唯一步骤是在Global.asax.cs中。
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文件之前,我尝试呈现如下:
<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 ……
考虑到我正在尝试完成基本任务,我不确定此时什么可能是空的。在启动分析器之前是否需要进行某种额外的设置?会不会是路由问题?
发布于 2014-04-22 21:25:13
在这种情况下,解决方案似乎是只使用标准的MiniProfiler库,而不是ServiceStack中包含的库。
初始设置
在Nuget包安装程序中,我运行了:
Install-Package MiniProfiler
Install-Package MiniProfiler.MVC4我以以下方式修改了global.asax:
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标记结束之前,我放置了:
@MiniProfiler.RenderIncludes()
</body>
</html>分析DB连接
在返回我的OrmLiteConnectionFactory的代码部分,我使用以下代码:
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和连接。
https://stackoverflow.com/questions/22842414
复制相似问题