c# - 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);
}
}
}
解决方案
您可以简单地在您的网页中使用 JavaScript 警报而不是 WebForm。
alert("Your Message");
推荐阅读
- sql - 存储点是否在 SQL 中的多边形中的结果
- .net - Restore-PowerAppEnvironment cmdlet 引发错误“无法识别为 cmdlet 的名称”
- python - txt文件中的字符串不等于校验和文件
- laravel - Laravel Dusk ERR_CONNECTION_REFUSED 访问本地主机
- openapi - 如何使 OpenApi Generator (typescript-angular) 生成没有“io-swagger-models-”前缀的模型文件?
- python - 用正则表达式将字符串分成组?
- azure - Azure 应用配置上的异常高请求
- palantir-foundry - Palantir Foundry 今天会导出到 Google Cloud Buckets 吗?
- javascript - 如何在 MVC 页面上使用 JavaScript '@'。错误 - {"\"') + 1);\" 在代码块的开头无效
- discord.js - Discord 自动消息脚本