为什么我的ASP.NET Web表单Load事件需要这么长时间?

时间:2010-01-22 21:27:14

标签: asp.net trace

我有一个ASP.NET 2.0 Web表单,需要花费大约30秒才能加载。我想知道发生了什么。我已经启用了跟踪并输入了一大堆Trace.Write语句,所以我希望能看到发生了什么。结果很奇怪。他们看起来像这样......

aspx.page开始加载0.000245093984962406
MyEvent1 0.000446804511278195
MyEvent2 0.000464654135338346
MyEvent3 0.000477984962406015
aspx.page End Load 23.9897560037594

因此我放入的所有Trace语句(MyEvent1,MyEvent2,MyEvent3)都会非常快速地触发。我输入的最后一个Trace语句就在Page_Load事件的末尾。那么有人能告诉我在Page_Load事件中的最终语句之后但在End Load发生之前可能发生了什么吗?我无法弄清楚这可能导致这么长时间。还有其他方法可以解决在Page_Load事件期间发生的事情吗?

更新 - 添加代码

     protected void Page_Load(object sender, EventArgs e)
     {
        Trace.Write("Starting Page Load");

        if (!Page.IsPostBack)
        {
            Trace.Write("Setting Body Tag and Meta Tags");
            HtmlGenericControl _mainBodyTag = (HtmlGenericControl)Page.FindControl("mainBodyTag");
            _mainBodyTag.Attributes["class"] = "drill membership";

            HtmlMeta _meta = new HtmlMeta();
            _meta.Name = "publication_date";
            _meta.Content = Sitecore.Context.Item.Statistics.Updated.ToShortDateString();
            Page.Header.Controls.Add(_meta);

            Trace.Write("Binding data");
            this.BindData();
        }
    }

    protected void BindData()
    { 
        //Feature
        Trace.Write("Setting Featured Item Info");
        litFeatureType.Text = "Report";
        hypTitle.Text = _feature.Fields["Title"].Value;
        hypTitle.NavigateUrl = LinkManager.GetItemUrl(_feature);
        hypReadMore.NavigateUrl = LinkManager.GetItemUrl(_feature);
        hypFeature.NavigateUrl = LinkManager.GetItemUrl(_feature);
        litFeatureText.Text = _feature.Fields["ShortDescription"].Value;
        litDate.Text = ((DateField)_feature.Fields["ReleaseDate"]).DateTime.ToShortDateString();
        litLocation.Visible = false;
        pnlMeeting.Visible = false;

        //News
        Trace.Write("Getting Member News");
        List<Item> _memberNews = _repository.GetMemberNews();
        rptNews.DataSource = _memberNews;
        rptNews.DataBind();

        //Lower Left
        Trace.Write("Getting lower left content");
        Item _home = Sitecore.Context.Database.SelectSingleItem("/sitecore/Content/Home");
        litLowerLeftContent.Text = _home.Fields["Lower Left Content"].Value;

        //Lower Right
        Trace.Write("Getting lower right content");
        litLowerRightContent.Text = _home.Fields["Lower Right Content"].Value;

        //Other Member Resources
        Trace.Write("Getting member resources items");
        Item _memberHome = Sitecore.Context.Database.SelectSingleItem("/sitecore/Content/Home/Member");
        rptMenu1.DataSource = _memberHome.Children;
        rptMenu1.DataBind();

        //Membership Stats
        Trace.Write("Getting membership stats");
        List<MembershipStat> _stats = _repository.GetMembershipStats();
        rptStats.DataSource = _stats;
        rptStats.DataBind();
        litTotal.Text = _totalCount.ToString();

        //Rail Content
        litRailContent.Text = _home.Fields["Right Rail Middle Content"].Value;

        Trace.Write("Finished");
    }

更新 - 添加跟踪输出示例:

Binding data    0.000103338345864662    0.000069
Setting Featured Item info  0.000174093984962406    0.000051
Getting Member News 0.000461293233082707    0.000287
Getting lower left content  0.0328178270676692  0.032357
Getting lower right content 0.0333527706766917  0.000535
Getting member resources items  0.0333826090225564  0.000030
Getting membership stats    0.130918973684211   0.097536
Finished    0.244487176691729   0.023386
aspx.page   End Load    23.9897560037594    23.745269
aspx.page   Begin LoadComplete  23.9898036541353    0.000048
aspx.page   End LoadComplete    23.9898190150376    0.000015
aspx.page   Begin PreRender 23.9898322293233    0.000013
aspx.page   End PreRender   23.9901133834586    0.000281
aspx.page   Begin PreRenderComplete 23.9901457819549    0.000032
aspx.page   End PreRenderComplete   23.9901602744361    0.000014
aspx.page   Begin SaveState 24.0240230714286    0.033863
aspx.page   End SaveState   24.0283510075188    0.004328
aspx.page   Begin SaveStateComplete 24.0283821616541    0.000031
aspx.page   End SaveStateComplete   24.0283963759398    0.000014
aspx.page   Begin Render    24.0284089849624    0.000013
aspx.page   End Render  24.0736610977444    0.045252

2 个答案:

答案 0 :(得分:4)

您使用的是母版页吗?页面上的任何用户控件或自定义服务器控件?如果是这样,您可能需要调查这些控件中的Page_Load。

答案 1 :(得分:1)

如果可能,请考虑将远程调试会话附加到生产服务器。然后,您应该能够设置断点等,并查看确切的内容。