---
title: Browser monitoring and the .NET agent
source: https://docs.newrelic.com/docs/apm/agents/net-agent/other-features/browser-monitoring-net-agent
---

With the .NET agent, you can add [browser monitoring](https://docs.newrelic.com/docs/browser/new-relic-browser/getting-started/introduction-new-relic-browser) instrumentation to your webpages. Before you use browser with your .NET agent, refer to the [.NET agent release notes](https://docs.newrelic.com/docs/release-notes/agent-release-notes/net-release-notes), and make sure you have the [installed the latest .NET agent release](https://docs.newrelic.com/docs/agents/net-agent/installation/install-net-agent-windows).

Follow the [.NET agent requirements](https://docs.newrelic.com/docs/agents/net-agent/getting-started/introduction-new-relic-net#extend) to [install browser monitoring](https://docs.newrelic.com/docs/browser/new-relic-browser/installation/install-new-relic-browser-agent). Then follow the procedures in this document to manually instrument the .NET agent.

## Auto-instrumentation [#auto_instrumentation]

> #### ⚠️ IMPORTANT
>
> Auto-instrumentation is only available for .NET Framework web apps and .NET Core v6.0 and later web apps. Auto-instrumentation is unavailable for ASP.NET Core v5.0 and earlier applications even if they're monitored by the .NET agent.

With browser auto-instrumentation, the .NET agent automatically injects the browser JavaScript header into any page that has a `content-type` of `text/html` and also has a `<head>` tag within the page.
[Browser auto-instrumentation](https://docs.newrelic.com/docs/agents/net-agent/configuration/net-agent-configuration/#browser_monitoring) is enabled by default.

The `<head>` tag search starts at the beginning of the DOM. The .NET agent injects the JavaScript header through the addition of an `HttpModule` that modifies the page using HTTP response filters before streaming the content to the user.

The first time you enable auto-instrumentation, you may need to clean your `asp.net` cache directory so that aspx pages are recompiled. Use the following command:

```bash
flush_dotnet_temp.cmd
```

With this injection, previously functioning pages may stop working if a `content-type` is not set correctly. To correct, review and update the `content-types` in your app or [disable auto-instrumentation](https://docs.newrelic.com/docs/agents/net-agent/other-features/browser-monitoring-net-agent/#disable_instrumentation).

## Manual instrumentation via agent API [#manual_instrumentation]

If you cannot enable auto-instrumentation, you can still include the browser agent manually by using the New Relic .NET agent API and including appropriate code in your pages.

1.  To download the `NewRelic.Api.Agent.dll`, re-run the installation and reference the `.dll`:

    -   From the New Relic .NET agent directory, select the **New Relic.Net** agent section, then select **API Assembly**.
    -   NuGet: Install and reference the **.dll** by running `Install-package NewRelic.Agent.Api`.
2.  To set up your web application to call the New Relic .NET agent API, add a reference to **`NewRelic.Api.Agent.dll`** to your project.
3.  Optional: If you are modifying the deployed application directory on the web server, copy **`NewRelic.Api.Agent.dll`** into the application's **`bin`** directory.
4.  Call the API in your `<head>` tag. If a meta-tag with the `X-UA-COMPATIBLE http-equiv` attribute exists, set it after that meta tag.

**.NET Web Forms view engine**

When using .NET Web Forms view engine, be sure to use `=` and not `:`. That way the view engine will recognize the string of HTML returned from the API as HTML / JavaScript and render it appropriately.

If you are using .NET ASP Web Forms with master pages, add the header manually by calling [`GetBrowserTimingHeader()`](https://docs.newrelic.com/docs/agents/net-agent/net-agent-api/getbrowsertimingheader-net-agent) in your master page under the `<head>` tag:

````aspnet
<%= NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader() %>
```

Import the namespace with:

```aspnet
<%@ Import Namespace="NewRelic.Api.Agent" %>
```

````

**Other view engines such as Razor**

For other view engines such as [Razor](https://en.wikipedia.org/wiki/ASP.NET_Razor), you can use the [`GetBrowserTimingHeader()`](https://docs.newrelic.com/docs/agents/net-agent/net-agent-api/getbrowsertimingheader-net-agent) method to generate the header string. Here is a Razor-based view example:

````razor
<!DOCTYPE html>
<html lang="en">
  <head>
    @Html.Raw(NewRelic.Api.Agent.NewRelic.GetBrowserTimingHeader())
    ...
  </head>
</html>
```

````

**.NET MVC**

When using .NET MVC, call the `Html.Raw` helper. That way, .NET MVC will recognize the string of HTML returned from the API as HTML / JavaScript and render it appropriately.

## Manual instrumentation with copy/paste [#copy-paste]

When enabling browser monitoring, you can manually insert the JavaScript snippet into your app's webpages. The copy/paste option gives you control over the exact placement of our JavaScript snippet, which is required to monitor the webpage's performance. For instructions on enabling browser monitoring with copy/paste, refer to our [Browser documentation](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/#copy-paste).

## Disable instrumentation [#disable_instrumentation]

To disable instrumentation:

**Disable auto-instrumentation**

To fully disable auto-instrumentation, edit **`newrelic.config`** and set the [`browserMonitoring` `autoInstrument` flag](https://docs.newrelic.com/docs/agents/net-agent/installation-configuration/net-agent-configuration#browsermon-autoInstrument) to `false`:

````xml
<!-- disable auto instrumentation -->
<browserMonitoring autoInstrument="false"/>
```

Alternatively, you can use an environment variable: `NEW_RELIC_BROWSER_MONITORING_AUTO_INSTRUMENT= 0 | false` to fully disable auto-instrumentation.

If you only want to disable ASP.NET Core 6+ browser instrumentation, set `NEW_RELIC_ENABLE_ASPNETCORE6PLUS_BROWSER_INJECTION= 0 | false`

<Callout variant="important">
  If you change the flag or uninstall the .NET agent, be sure to flush your cache again so that references to the agent are removed from compiled files.
</Callout>

````

**Disable auto-instrumentation on a particular view**

To disable only auto-instrumentation on a particular view, use the agent API call `DisableBrowserMonitoring()`. Add this call in any view where browser scripts are not needed or wanted. Put this API call as close as possible to the top of the view where you want it disabled.

**Disable both automatic and manual instrumentation on a particular view**

To disable both auto-instrumentation and manual instrumentation for individual webpages, use the agent API call [`DisableBrowserMonitoring(true)`](https://docs.newrelic.com/docs/agents/net-agent/net-agent-api/disablebrowsermonitoring-net-agent).

## Troubleshooting

Follow the troubleshooting procedures if you are [unable to view any browser timing data](https://docs.newrelic.com/docs/agents/net-agent/troubleshooting/no-page-load-timing-data-appears-net).
