> ## Documentation Index
> Fetch the complete documentation index at: https://docs.waniwani.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# ASP.NET on IIS

> Add the Waniwani relay module to a classic ASP.NET site that runs on IIS.

Use this setup when your site is a classic ASP.NET site (System.Web, for example MVC 5 or Web Forms) and IIS serves it. The relay is the `Waniwani.Relay.AspNet` NuGet package. It is an IIS module, so you add it to `web.config` and do not change your code. You need .NET Framework 4.6.2 or later, and IIS in integrated mode.

The relay records the agent visits, serves [agent pages](https://docs.waniwani.ai/agent-traffic/agent-pages.md) and [blocks agents](https://docs.waniwani.ai/agent-traffic/blocking.md). You turn agent pages and blocking on and off in the dashboard, with no deploy.

## Add the package

Run this command in the Package Manager Console of Visual Studio, in the web project:

```powershell theme={null}
Install-Package Waniwani.Relay.AspNet
```

## Edit web.config

The setup screen gives you these lines with your region. Put your key in place of `PASTE_THE_KEY`:

```xml web.config theme={null}
<configuration>
  <appSettings>
    <add key="Waniwani:AgentTrafficKey" value="PASTE_THE_KEY" />
    <add key="Waniwani:ClientIpHeader" value="X-Forwarded-For" />
    <add key="Waniwani:TrustedProxies" value="" />
  </appSettings>
  <system.webServer>
    <modules>
      <add name="WaniwaniRelay" type="Waniwani.Relay.AspNet.WaniwaniRelayModule, Waniwani.Relay.AspNet" />
    </modules>
  </system.webServer>
</configuration>
```

Do not add `preCondition="managedHandler"` to the module. Without it, the module also runs for static files such as `/llms.txt`.

For an organization in the [EU region](https://docs.waniwani.ai/platform/regions.md), the setup screen adds `<add key="Waniwani:Region" value="eu" />`.

## Behind a CDN or a load balancer

When a CDN, a WAF or a load balancer is in front of IIS, IIS sees its address on each request, not the address of the visitor. The CDN puts the visitor address in a request header, for example `X-Forwarded-For`. Ask your CDN provider which header it uses and which addresses it connects from. Then set:

* `Waniwani:ClientIpHeader` to the name of that header.
* `Waniwani:TrustedProxies` to the addresses and CIDR ranges of the CDN and the load balancers, separated by commas.

The relay reads the header only when the request comes from a trusted address. Thus a visitor cannot send a false `X-Forwarded-For`. Without these two settings, detection by `User-Agent` still works, but detection by IP range does not.

When IIS gets the requests directly, remove the two lines.

## Network access

IIS must make outbound HTTPS calls to these hosts:

| Region | Hosts |
| - | - |
| US | `app.waniwani.ai` and `pages.waniwani.tools` |
| EU | `eu.app.waniwani.ai` and `eu-pages.waniwani.tools` |

When the relay cannot get to Waniwani, your site works as usual. The relay drops the events and does not serve agent pages.

## Deploy and check

Deploy the site. In the setup screen, enter the address of one of your pages and click **Check now**.

## Settings

| Key | Default | Use |
| - | - | - |
| `Waniwani:AgentTrafficKey` | The `WANIWANI_AGENT_TRAFFIC_KEY` environment variable | The key from the setup screen |
| `Waniwani:Region` | `us` | `us` or `eu` |
| `Waniwani:ClientIpHeader` | None | The header that has the visitor address |
| `Waniwani:TrustedProxies` | None | The addresses of your CDN and load balancers |
| `Waniwani:Omit` | None | Headers, or the fields `userAgent`, `referer` and `matchKey`, to leave out of every event |
| `Waniwani:Enabled` | `true` | Set it to `false` to stop the relay without a deploy |

## Notes

* A CDN can answer an agent from its cache. Then the request does not get to IIS, and the relay does not see it. Make sure that your CDN does not keep HTML pages for agents, or that it sends requests with `Accept: text/markdown` to IIS.
* For paths with agent pages, the relay turns off the IIS kernel cache.
* The package is open source. The [README](https://github.com/WaniWani-AI/relay/tree/main/dotnet#readme) has all the settings, and ASP.NET Core.
* To open this setup directly, use `https://app.waniwani.ai/agent-traffic/websites/new?platform=aspnet`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.