C# MiniProfiler在ASP.NET网站上也能工作吗

C# MiniProfiler在ASP.NET网站上也能工作吗,c#,asp.net,profiler,mvc-mini-profiler,C#,Asp.net,Profiler,Mvc Mini Profiler,我已经完成了MiniProfiler文档中给出的所有步骤,并且能够看到特定调用的结果 但是,当尝试将其添加到Global.asax页面时,会抛出如下错误: 异常详细信息:System.Web.HttpException:请求在此上下文中不可用 MiniProfiler是否也适用于ASP.NET网站,还是仅适用于web应用程序 我通过NuGet MiniProfiler添加包 Global.asax页面代码 <%@ Application Language="C#" %> <%@

我已经完成了MiniProfiler文档中给出的所有步骤,并且能够看到特定调用的结果

但是,当尝试将其添加到Global.asax页面时,会抛出如下错误:

异常详细信息:System.Web.HttpException:请求在此上下文中不可用

MiniProfiler是否也适用于ASP.NET网站,还是仅适用于web应用程序

我通过NuGet MiniProfiler添加包

Global.asax页面代码

<%@ Application Language="C#" %>
<%@ Import Namespace="StackExchange.Profiling" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        MiniProfiler.Start();
    }

    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        MiniProfiler.Stop();
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }

</script>

无效应用程序\u启动(对象发送方,事件参数e)
{
//在应用程序启动时运行的代码
MiniProfiler.Start();
}
无效应用程序\u结束(对象发送方,事件参数e)
{
//应用程序关闭时运行的代码
}
无效应用程序错误(对象发送方,事件参数e)
{ 
//发生未处理错误时运行的代码
}
无效会话\u启动(对象发送方,事件参数e)
{
//启动新会话时运行的代码
MiniProfiler.Stop();
}
无效会话\u结束(对象发送方,事件参数e)
{
//会话结束时运行的代码。
//注意:只有在sessionstate模式下才会引发Session_End事件
//在Web.config文件中设置为InProc。如果会话模式设置为StateServer
//或SQLServer,则不会引发该事件。
}

我有点错了,上次我在ASP.MVC中使用它。但我已经设法为您提供了一个工作示例:

Global.ASAX

private bool isStarted;

protected void Application_Start(object sender, EventArgs e)
{
    this.isStarted = false;
}

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (!isStarted)
    {
         this.isStarted = true;

         if (Request.IsLocal) 
         {
              MiniProfiler.Start();   
         }
    }
}

protected void Application_EndRequest(object sender, EventArgs e)
{
     MiniProfiler.Stop();
}
Page.aspx

protected void Page_Load(object sender, EventArgs e)
{
  var miniprofiler = MiniProfiler.Current;

  var htmlString = miniprofiler.Render();

  Literal1.Text = htmlString.ToString();
}
这将需要一些调整,但至少它会给你一些工作。不过,我并不完全相信mini profiler设计用于ASP.NETWeb表单


噢,
Literal1
只是一个标准的文字控件。

你能在Global.asax页面上发布你的代码吗?我确信我已经在ASP.net中使用了MiniProfiler。请检查编辑。我在htmlString中只得到一个空字符串,顺便说一句,MiniProfiler对我来说是空的:(