Adding Application Insight For An Existing ASP.NET Web Application

Introduction

This article will guide you to add Application Insight on Azure for an existing ASP.NET Web Application. If you are starting a new project or have an existing Web Application and want to use Application Insights, Visual Studio 2013 and later now has a built-in capability to add Application Insights to your Application.

Note

Here, I will be working with a Web app, which was already built by me namely “MyWebsite”.

The links are given below for the reference.

  • Click here for kick-start to Application Insights on Microsoft Azure.
  • Click here for creating an Application Insight on Microsoft Azure.
  • Click here for configuring your Web Application to use Application Insight.

Pre-requisites

  1. Microsoft Azure account- Click here to get a free Microsoft Azure account. (this will be a temporary one).
  2. Visual Studio 2015– Click here to download Visual Studio 2015.

Follow the steps given below.

Step 1

Open “MyWebsite” ASP.NET Web Application in Visual studio 2013.

Note

This is an existing ASP.NET Web Application, which you already have and you want to add “Application Insights” to capture telemetry data.

Step 2

Go to “Solution Explorer” and right click on the project “MyWebsite” and you will see “Add Application Insights Telemetry”.

Note

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



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. Enter Microsoft account credentials to login:



Step 3

After successfully signing in, you will get the options to either use an existing “Application Insight” resource or create a new.



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



Step 4

After entering all the values, click on the blue button “Add Application Insights To Project”. You will observe that Visual Studio will be adding a few “NuGet Packages” to the project to enable it to use “Application Insights”.



Step 5

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.



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



Step 6

Now, right click on the project in Solution Explorer and click “Manager NuGet Packages”

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



Step 7

Run the Website locally by pressing “Ctrl+F5” to ensure it runs fine locally. Now, we will host this Website on MicroSoft Azue Websites and test it live on Cloud. Right click on the “Website” project in Solution Explorer again and click Publish. Select “Microsoft Azure Websites”. 



Step 8

This brings up the list of Websites already there and an option to create a new one. Click New.



Enter the values in the “Create a Site On Microsoft Azure” Window and click create.



Step 9

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



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



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



Step 10

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


Similar Articles