Add Application Insight In Existing ASP.NET Web Application

Introduction

Do you have an existing Web Application and want to use Application Insights? Just get on to Visual Studio --  Visual Studio 2013 now has built-in capability to add Application Insights to your application.

Follow the steps given below now to add Application Insight in the existing ASP .NET Application:

Step 1: Open the ASP.NET Web Application in Visual studio 2013.

Step 2: This is an existing ASP.NET Web Application that you already have and you want to add “Application Insights” to capture telemetry data. Hence, go to the “Solution Explorer” and right click on project “MyWebsite” and you will see “Add Application Insights Telemetry”.

You need “Visual Studio 2013 Update 3” or more to get this option in the IDE.

Visual Studio 2013 Update 3

Step 3: Click “Add Application Insights Telemetry” and it will show option to “Sign-in” to Azure account to proceed further.

Click “Sign-In with your Azure Account to get started”. You will get the Sign-In page:

Sign-In with your Azure Account

After successfully signing in, you will get the options to either use an existing “Application Insight” resource or create a new one now, as shown below:

Application Insight

You can also click “Configure settings” to enter specific values:

Configure settings

After entering all the values, click the blue button “Add Application Insights To Project”.

You will observe that Visual Studio will be adding few “Nuget Packages” to the project to enable “Application Insights”.

project to enable

Step 4: After Visual Studio has finished adding “Application Insights” to your project, you will see couple of changes.

First, you will see a configuration file added to your project:

configuration

Open the Web.config file and check the modules added to the configuration:

Web.config file

Step 5: Now, right click the project in Solution Explorer and click “Manager Nuget Packages

In the “Installed Packages” section, you will see the following “Nuget Packages” installed to enable your application to use “Application Insights”:

Installed Packages

Run the Website locally by pressing “Ctrl+F5” to ensure it runs fine, locally.

Now, we will host this Website on MicroSoftAzue Web Sites and test it live on the Cloud.

Right click on the “Website” project in Solution Explorer again and click “Publish”. Select “Microsoft Azure Websites”.

Microsoft Azure Websites

This brings up the list of Websites, which are already there and the option to create a new one also comes. Click “New”.

New

Step 6: Enter the values in the “Create a Site On Microsoft Azure” Window and click Create:

Create a Site On Microsoft Azure

After creating the Website, Visual Studio will automatically download the publishing project and will present you with an option to go ahead with the “Publish:



Click “Next” and then “Publish” button to start publishing the Website. You will observe the verbose logging at the bottom of Visual Studio in “Output” Window:

Output

Once the Publish is finished, the Visual Studio will Pop-up a new browse instance with the Website URL.

website

Now browse the “Default.aspx” on your Website hosted on Microsoft Azure. It will keep refreshing itself, after every 2 seconds.

Open another tab and browse “TriggerCPU.aspx” page on your Website hosted on Microsoft Azure. Click on “Trigger CPU” to log some Server telemetry data on “Application Insights”.

Trigger CPU

Up Next
    Ebook Download
    View all
    Learn
    View all