首页 > 解决方案 > ASP.Net 页面第一次运行缓慢如果我使用 System.Web.Ui 命名空间

问题描述

我有一个使用 C# 用 ASP.Net Web Form 4.0 编写的 Web 应用程序,生产机器是带有 IIS 8.5.9600.16384 和 SQL Server 2014 的 Windows Server 2012 R2。

应用程序中的每个页面都运行得很快,但是任何使用命名空间 system.Web.Ui 的页面我第一次打开它需要将近 2 分钟,然后我可以快速打开任何页面,如果没有人打开这个页面近 25 分钟问题会再次出现,我需要再等 2 分钟才能再次打开它。

注意:这个问题只在生产机器上我没有在开发机器上,在开发机器上一切正常。问题只是当我使用命名空间 system.Web.Ui 不是第一个应用程序页面或整个应用程序。

我尝试将应用程序池中的空闲超时设置为 0 像这个示例设置空闲超时示例,在几个小时内一切都会好起来,但如果没有人使用该站点,1 天后问题就会返回。

请帮助诊断和解决这个问题。

前端代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h3>TestPage</h3>
</asp:Content>

后端代码:

   using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"AlertBox","Alert('Hello World');",true);
        }
    }
}

标签: c#asp.netwebforms

解决方案


您可以简单地在您的网页中使用 JavaScript 警报而不是 WebForm。

alert("Your Message");

推荐阅读