1

我一直按照上显示的设置

http://miniprofiler.com/

EntityFramework v4.3.1在我的 Web 应用程序中引用 NuGet 包只是为了开始MiniProfiler工作,但 EF.edmx和生成的模型位于单独的引用项目中。

我也在使用

MiniProfile.EF v2.1.0
MiniProfiler v2.1.0

我的网络应用程序global.asax.cs看起来像这样

public class Global : HttpApplication
{
    private void Application_Start(object sender, EventArgs e)
    {
        MiniProfilerEF.Initialize();
        //MiniProfilerEF.InitializeEF42();

        // Code that runs on application startup
        InitProfilerSettings();
    }

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
        }
    }

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


    private void InitProfilerSettings()
    {
        // some things should never be seen
        var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();
        ignored.Add("/Styles/");
        ignored.Add("/Scripts/");
        ignored.Add("/files/");
        ignored.Add("/images/");
        MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();

        MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
    }

}

我在我的中添加了一个处理程序web.config,如下所示

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    <handlers>
        <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
  </system.webServer>

在关闭正文标记之前,我已将以下内容添加到最后的母版页中

<%= StackExchange.Profiling.MiniProfiler.RenderIncludes() %>

我只能通过执行以下操作来设置带有配置文件连接的上下文,否则EntityConnection在 DBContext 上执行 LINQ 查询期间使用时会出现运行时错误。

         //var _modelContext = new Entities();
        // ConfigurationManager.ConnectionStrings["Entities"].ConnectionString
        //var profiledConnection = new EFProfiledDbConnection(new Entities().Connection, MiniProfiler.Current);
        var profiledConnection = new EFProfiledDbConnection(new SqlConnection(ConfigurationManager.ConnectionStrings["EntitiesSql"].ConnectionString), MiniProfiler.Current);
        var _modelContext = ObjectContextUtils.CreateObjectContext<Entities>(profiledConnection); 

所有这些似乎都有效,我可以在本地运行我的应用程序,我可以查看页面源代码并查看此脚本块,在 Chrome 中我可以选择 include.js 链接并查看内容

<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="adf7a5f4-482d-4f65-b09e-e3c59b157134" data-ids="adf7a5f4-482d-4f65-b09e-e3c59b157134" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>

但是,在 Chrome 中查看控制台时,我收到以下消息

POST http://localhost:54406/mini-profiler-resources/results 404 (Not Found) 

我希望添加相关的处理程序可以解决我的问题:(但它没有。

任何帮助表示赞赏。

4

0 回答 0