Application getting slow when open the application for the first time - c#

I have developed a application in ASP.NET using c#. The entire application working fine but the problem is when I open the application for first time it running very slow. i.e. its taking so much time to load a page like home page or any other page. But when I reopen that page then that page opens quickly as I expect. Even whenever application getting session expired and relogin into application its taking so much time again to load all the pages for the first time, where from 2nd time to opens that pages its not happening. So can anybody tell me what is the problem occuring here.

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:
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.
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.
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.

Check your site in firebug in .net tab there you will find which part of your page take much time to load,
there might be some exceptions or some code errors in client side language.
Try to use less sessions
and debug your code to clarify no extra looping of code
(sorry for bad English but hopefully you have got my point)

Related

Debug in Browser?

Asp.net app runs fine without issues on localhost. However, when published and I access via Chrome/Edge it does not work as intended (will not load the page when button is clicked). Is there a way to see what the live published version is doing in the code?
Tried replicating the issue in Visual Studio Debug, but could not recreate it
ASP.NET code is executed on the server, so there’s not a lot to see in the browser. You can use the Chrome/Edge developer tools (F12) to see what it is seeing, though. There might be helpful information in the console and especially in the network tab, where you can see what requests the app is making and what the server’s responses to them are in some detail. (I’ve had problems with web apps making assumptions about their path that didn’t apply once they were installed.) If you have sufficient access to the server, it might be helpful to look at its logs, especially if your app is returing 500 errors. It’s often a good idea to implement a lot of logging in your web app, using NLog, log4net, or similar libraries. Again, though, you have to have permission to write the logs and to look at them when you need to.
Please follow the normal debugging workflow:
Load a page in your browser.
Open the developer tools.
Select Sources tab; Open HTML file; Open JavaScript file.
Set a breakpoint in the JavaScript file.
Reload the browser page. Loading stops at the breakpoint.
Debug until you find the problem.
Fix the problem (in your usual code editor, not in the developer tools) and save the file.
Debugging tools are supported by most browsers and environments, which make debugging easier by stepping through the code so you can see what's going on.

Slow startup (asp.net website, entityframework)

I know this kind of question has been asked manytimes, but those topics I found didn't help me much.
I've a asp.net website, very simple one, with a very simple default page, which require some data (just some) from the database. I'm using the Enity Ado.net framework for the database. I also set the Model's "Lazy Loading Enabled" to False. I just don't know why it took so long to start the first time I access the website. After that, the speed is ok.
I'll be very appreciated if someone can help me to find what'm I doing wrong here.
Thanks in advance!
If you go and search for it on Microsofts´ Website you will find enough resources that will answer your question. I believe to answer questions here at SO while there exist somewhere else, is just wrong.
Compiling on First Request
By default, ASP.NET Web pages and code
files are compiled dynamically when users first request a resource,
such as an ASP.NET page (.aspx file), from a Web site. After pages and
code files have been compiled the first time, the compiled resources
are cached, so that subsequent requests to the same page are extremely
efficient. ASP.NET supports the dynamic compilation of ASP.NET pages
(.aspx files), ASP.NET Web services (.asmx files), ASP.NET HTTP
handlers (.ashx files) and ASP.NET application files (Global.asax), as
well as other files, such as source code and class files. For more
information about ASP.NET file types, see Web Site File Types. For
more information about the ASP.NET compilation process, see the
"Compilation Life Cycle" section of ASP.NET Application Life Cycle
Overview.
Source

How to implement page counter for an existing ASP.NET web application

I am finding a good way to implement Page Counter Statistic for internal web application (so maybe I can not use Google Analytics to help me).
I want to find out which page in my web application that user does not visit anymore. So I can investigate the reason why there is no hit to that page. If it has a bug or that page is not necessary anymore.
The easy way that comes to mind is to add every page with some line of codes to update the page page view. But there are so many page in my web, so this will take a lot of time.
So is there any other way to make a simple web page statistic with minimize line of codes.
For more information
- Every user have to log in before using this web.
- There is session to store user's ID.
- I use .NET 1.1 as an environment and plan to migrate to .NET 2.0+ in the future.
- Page stat is not show on web, I just want the hit count and then analyze it.
Google Analytics is probably your best bet. Although your site is internal, Google Analytics will still work so long as you are able to hit their server from within your network. I've used it on intranet sites before without any issues.
You use ashx files and invoke it via markup (i.e. as a jquery invocation or as using an image tag) or you add an HTTP module. Both can be implemented without recompiling-- just adding one more .dll to the bin and editing the web.config. There is not enough space in this text box to give full justice to the steps necessary to write a http module or handler and a hit counter.

website - compile classes -update in the server

I have created a website using ASP.Net and running on port 8080. When server is still running, I can some changes in the code. Interestingly, those changes are reflected on my site when I pressed refresh button. I just wondering with this because I guess we have to compile and rebuild site to see new changes.
thanks !
Yes, WebSite working in this way. WebApplication requires rebuild all because all codebehind logic are built in DLL of WebProject
See this MSDN article: Comparing Web Site Projects and Web Application Projects
Web Site Projects
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and
then simply refresh the page in the browser).
That depends on if you have an asp web site of a web application. Take a look at this msdn page for more info.
When you have the full source for an ASP.NET web site (not a web application) running, your site will be dynamically compiled, and changes you make will be detected.
From the MSDN documentation, Understanding ASP.NET Dynamic Compilation:
Any changes to a dynamically compiled file will automatically invalidate the file's cached compiled assembly and trigger recompilation of all affected resources. The next time a request to the code is made, ASP.NET recognizes that the code has changed and recompiles the affected resources of the Web application. This system enables you to quickly develop applications with a minimum of compilation processing overhead. (Note that depending on the change to the resources, the result can range from recompiling a single page to recompiling the whole Web site.)

Can using server-side scripting delimiters (<% %>) cause compilations during runtime?

I am occasionally getting "Application compilation is starting." event in my Event Log and I can't identify what's causing it. I think I may try this - http://blogs.msdn.com/b/tess/archive/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing.aspx - but before I do that I was curious if I can identify the problem without starting to mess with something unknown.
I have used <%= %> and <%# %> tags throughout the app so I am wondering if this is what's causing the problems. On couple spots I have embedded C# code (using ) so that may add to it?
Precompiling the app is also valid choice for me, I just don't want to end in position in which I need execute precompilation command on the server every time I upload some changes to the server. Currently on my dev machine I've followed advices from this link - http://mikehadlow.blogspot.com/2008/05/compiling-aspx-templates-using.html - and it does awesome job as it allows me to identify errors in C# code in .aspx pages during build in Visual Studio. However, I presume precompilation results are not stored in my website directory (and won't be published when I use Publish option).
Ideally, I want to stay in position I am with default Web Application model with addition of automatically running compilation as soon as I upload changed .aspx or .ascx over FTP (not waiting for user's http request). Am I asking too much, or is this possible to setup?
From my research it seems it can.
Because nobody responded I'll accept this as answer.

Categories