C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Time elasped in page execution


Posted Date: 21 Oct 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Atal Bihari UpadhyayMember Level: Gold    
Rating: 1 out of 5Points: 4



Time elasped in page execution

Here I am writing a simple utility to tell you how much time a asp page has taken for execution.

Normally, Beginrequest is first event to fire when we request a aspx page and Endrequest is the last event.

I have created a HTTPHandler to capture these events and alert time difference between begin request and end request.
How to apply this in your application:

Step 1: Copy following code into TimeClass.cs file and compile it from .net command prompt as :

csc /target:library TimeClass.dll

using System;

using System.Web;

namespace TimeClass

{

public class ShowTime : IHttpModule

{

private HttpApplication myApplication;

private DateTime BeginTime, EndTime;

public void Init(System.Web.HttpApplication application)

{

application.BeginRequest += new System.EventHandler(BeginRequest);

application.EndRequest += new System.EventHandler(EndRequest);

myApplication = application;

}

public void BeginRequest(object sender, EventArgs e)

{

BeginTime=DateTime.Now;

}

public void EndRequest(object sender, EventArgs e)

{

EndTime=DateTime.Now;

int time= EndTime.Millisecond-BeginTime.Millisecond;

myApplication.Response.Output.Write("<script>alert('Time Elasped={0}(in Milliseconds)');>/script>",time);

}

public void Dispose()

{

}

}

}

Step 2: Copy TimeClass.dll into bin folder of your web application.

step 3: Add following lines in your web.config file in system.web section

<system.web>

<httpModules>

<add type="TimeClass.ShowTime, TimeClass" name="ShowTime" />

</httpModules>

Step 4: Request any aspx page from your application. you will get alert message displaying how much time elasped in executing your application.

That's it. Hope it is helpful in measuring the performance of your application. Any comment/criticism is welcome.

Regards,

Atal.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Open new window in Asp.NET in .net way
Previous Resource: How to change the page content dynamically.
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use