Why is my ASP.NET web form Load event taking so lo

2019-07-28 03:54发布

问题:

I have an ASP.NET 2.0 web form that is taking almost 30 seconds to load. I am trying to figure out what is going on. I have enabled tracing and put in a whole bunch of Trace.Write statements so I can hopefully see what is going on. The results are very strange. They look like this...

aspx.page Begin Load 0.000245093984962406
MyEvent1 0.000446804511278195
MyEvent2 0.000464654135338346
MyEvent3 0.000477984962406015
aspx.page End Load 23.9897560037594

So all of the Trace statements that I put in (MyEvent1, MyEvent2, MyEvent3) fire very quickly. The last Trace statement that I put in is right at the end of the Page_Load event. So can anyone tell me what might be happening right after the final statement in the Page_Load event but before the End Load happens? I can't figure out what could be causing this to take so long. Is there some other way I can troubleshoot what is happening during the Page_Load event?

UPDATE - Adding code

     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");
    }

Updated - Adding trace output example:

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

回答1:

Are you using a master page? Any user controls or custom server controls on the page? If so, you may want to investigate the Page_Load in those controls.



回答2:

If possible, consider attaching a remote debug session to your production server. You should then be able to set breakpoints, etc, and see what, exactly, is going on.



标签: asp.net trace