3

我使用 c# 在 ASP.NET 中开发了一个应用程序。整个应用程序运行良好,但问题是当我第一次打开应用程序时它运行非常慢。即它需要花费大量时间来加载主页或任何其他页面之类的页面。但是当我重新打开该页面时,该页面会按我的预期快速打开。即使每当应用程序会话过期并重新登录到应用程序时,它也会再次花费大量时间来第一次加载所有页面,而从第二次打开该页面就不会发生。所以谁能告诉我这里发生了什么问题。

4

2 回答 2

6

The application is compiled on the first request.

Read this article by Microsoft.

Because ASP.NET compiles your Web site on first user request, you can simply copy your application's source code to the production Web server. However, ASP.NET also provides precompilation options that allow you to compile your Web site before it has been deployed, or to compile it after it has been deployed but before a user requests it. Precompilation has several advantages. It can improve the performance of your Web site on first request because there will be no lag time while ASP.NET compiles the site. Precompiling can also help you find errors that might otherwise be found only when a user requests a page. Finally, if you precompile the Web site before you deploy it, you can deploy the assemblies instead of the source code.

You can precompile a Web site using the ASP.NET compiler tool (ASPNET_Compiler.exe). The tool that provides the following precompilation options:

  1. In-place compilation This option performs the same compilation that occurs during dynamic compilation. Use this option to compile a Web site that has already been deployed to a production server.
  2. Non-updateable full precompilation Use this to compile an application and then copy the compiled output to the production server. All application code, markup, and UI code is compiled into assemblies. Placeholder files such as .aspx pages still exist so that you can perform file-specific tasks such as configure permissions, but the files contain no updateable code. In order to update any page or any code you must precompile the Web site again and deploy it again.
  3. Updateable precompilation This is similar to non-updateable full precompilation, except that UI elements such as .aspx pages and .ascx controls retain all their markup, UI code, and inline code, if any. You can update code in the file after it has been deployed; ASP.NET will detect changes to the file and recompile it. Note that code in a code-behind file (.vb or .cs file) built into assemblies during precompilation, and you therefore cannot change it without going through the precompilation and deployment steps again.

However, you mentioned that it's also slow if the session expired. Maybe you are loading too much into memory on session start. It's difficult to make a diagnosis without more informations.

于 2013-11-07T08:44:57.370 回答
0

在 .net 选项卡中的 firebug 中检查您的站点,您会发现页面的哪些部分需要很长时间才能加载,客户端语言中可能存在一些异常或一些代码错误。尝试使用更少的会话并调试您的代码以澄清没有额外的代码循环(抱歉英语不好,但希望您明白我的意思)

于 2013-11-07T09:02:56.043 回答