> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-installation-instructions/zen-firewall-for-dotnet/aspnet-framework.md).

# ASP.NET Framework（OWINを含む）

このガイドでは、Aikido の Zen Firewall をアプリケーションにインストールして設定する手順を順を追って説明します。以下の手順に従って、アプリケーションを保護しましょう。

問題や不具合が発生した場合は、サポートチャットまたは GitHub の issue まで遠慮なくご連絡ください

<https://github.com/AikidoSec/firewall-dotnet>

## 要件

* C#/.NET Framework 4.6以上（4.8.xまでテスト済み）。
* ASP.NET Framework（OWIN対応）。
* [Aikido アカウント](/docs/docs-ja/hajimeni/setting-up-your-account.md) & [Zen Firewall トークン](/docs/docs-ja/zen-firewall/zen-installation-instructions/creating-an-aikido-zen-firewall-token.md)

## インストールと設定

{% stepper %}
{% step %}
**Aikido による Zen Firewall をインストール**

.NET Framework 4.6 以上でプロジェクトが実行されるようにしてください。

NuGet からパッケージをインストールします:

```bash
dotnet add package Aikido.Zen.DotNetFramework
```

または、Package Manager Console で:

```powershell
Install-Package Aikido.Zen.DotNetFramework
```

トークンを次の場所に追加してください `Web.config`:

```xml
<appSettings>
  <add key="Aikido:AikidoToken" value="your-api-key" />
</appSettings>
```

アプリ起動時に Zen を開始します:

{% @aikido-custom-code/code-highlight language="csharp" content="! Global.asax.cs
+using Aikido.Zen.DotNetFramework;

protected void Application\_Start()
{
// other code

* Zen.Start();
  }" %}

OWIN を使用している場合:

{% @aikido-custom-code/code-highlight language="csharp" content="! Startup.cs
+using Aikido.Zen.DotNetFramework;

public void Configuration(IAppBuilder app)
{
// other code

* Zen.Start();
  }" %}
  {% endstep %}

{% step %}
**ユーザー識別とブロックを有効にする**

このミドルウェアを使用して現在のユーザーを識別し、ユーザーのブロックなどのユーザーベース機能を有効にします。

Zen Firewall が攻撃をブロックするためにこのミドルウェアを必要とすることはありません。コアの攻撃防御はこれなしで動作します。Zen にどのユーザーがリクエストを送っているかを認識させたい場合は、このミドルウェアを追加してください。

アプリケーションがユーザーを識別する方法に合わせて、例を調整してください。

{% @aikido-custom-code/code-highlight language="csharp" content="! Global.asax.cs
public void Application\_Start()
{

* Zen.SetUser(context => new User(context.User.Identity.Name, context.User.Identity.Name));
  Zen.Start();
  }" %}

OWIN を使用している場合:

{% @aikido-custom-code/code-highlight language="csharp" content="! Startup.cs
public void Configuration(IAppBuilder app)
{

* Zen.SetUser(context => new User(context.User.Identity.Name, context.User.Identity.Name));
  Zen.Start();
  }" %}
  {% endstep %}

{% step %}
**Zen Firewall をドライ／検出のみモードで起動**

トークンを環境変数として設定し、Aikido Zen エージェントがそれを取得できるようにしてください。まだトークンがない場合は、以下に従ってください [こちらの手順](/docs/docs-ja/zen-firewall/zen-installation-instructions/creating-an-aikido-zen-firewall-token.md).

```bash
AIKIDO_TOKEN=AIK_RUNTIME_
```

どのリクエストもブロックせずに期待どおり動作することを確認するため、アプリをドライモードで起動することを推奨します。誤検知を避けるため、Zen Firewall はステージング環境で2週間運用することを推奨します。

```bash
AIKIDO_BLOCK=false
```

{% hint style="info" %}
次を使用できます `AIKIDO_DEBUG=true` エージェントの動作に関するより詳細な情報を得るためにデバッグモードを有効にします。環境変数の詳細については： [環境変数による設定](/docs/docs-ja/zen-firewall/zen-installation-instructions/configuration-via-environment-variables.md)
{% endhint %}
{% endstep %}

{% step %}
**アプリをテスト**

ブラウザでアプリケーションを開き、いくつかの操作を行うか、いくつかのページを開いてください。Zen がアプリケーション内のルートを自動的に検出します。

{% hint style="info" %}
Zen は 10 分ごとにデータを Aikido に送信します
{% endhint %}

動作中のエージェントは、Zen アプリケーションの以下のページを確認することで検証できます：

* **イベント**: 「Application started」イベントが表示されるはずです。
* **ルート**: しばらくすると、アプリケーションのルートがメソッド、ルート、リクエストとともにここに表示され始めます。
* **インスタンス**: Zen がインストールされているアプリケーションのアクティブなインスタンス数が表示されるはずです。

<figure><img src="/files/bb6b16755cff4893513acdf0b399ab02ac7f5629" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**ダッシュボードでレート制限を設定**

Zen Firewall ミドルウェアを追加したら、Aikido ダッシュボードでレート制限を設定することで、ルートを総当たり攻撃から保護できるかテストできます。

1. 作成したアプリをクリックしてください。
2. へ移動してください **ルート** タブ。
3. 制限したいルートを見つけてクリック **レート制限の設定**.
4. 手順に従ってレート制限を設定します（例: 1 分あたり 5 リクエスト）。

![保護とレート制限オプションがある認証ルートを表示する API ルート管理インターフェース。](/files/e261faad47cc6b8291385535f551e58938a77367)

![POST /auth/login のレート制限を 1 分あたり 5 リクエストに設定します。](/files/532f8ebb75a40ac740e8c3d35685a3aeb1b7e97d)

**レート制限を確認する**

アプリを起動し、レート制限を設定したルートに 1 分以内に 5 回アクセスしてみてください。5 回目の試行後、レート制限エラーが表示されるはずです:

```
Aikido ファイアウォールによりレート制限されています。（あなたの IP: 1.2.3.4）
```

{% endstep %}

{% step %}
**次の手順**

Zen Firewall のインストールが正常に完了しました。おめでとうございます。何か問題が発生した場合や、ご不明点、機能のご要望がある場合は、遠慮なくサポートまでお問い合わせください。

これで、Zen Firewall が提供する多くの機能を使ってみることができます：

* [Zen Firewallでボットトラフィックをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-bot-traffic-with-zen-firewall.md)
* [Zen FirewallでTorトラフィックをブロックまたは監視する](/docs/docs-ja/zen-firewall/zen-features/blocking-tor-traffic-with-zen-firewall.md)
* [Zen Firewallでユーザーを追跡する](/docs/docs-ja/zen-firewall/zen-features/blocking-users-with-zen-firewall.md)
* [Zen Firewallで既知の脅威アクターをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-known-threat-actors-with-zen-firewall.md)
* [Zen Firewallで国別にトラフィックをブロックする](/docs/docs-ja/zen-firewall/zen-features/blocking-traffic-by-country-with-zen-firewall.md)
* [ルートのレート制限を設定する](/docs/docs-ja/zen-firewall/zen-features/setting-up-rate-limiting-for-routes.md)
* [アウトバウンドドメインを監視する](/docs/docs-ja/zen-firewall/zen-features/monitor-outbound-domains.md)

追加情報：

* [Zenのパフォーマンスと信頼性](/docs/docs-ja/zen-firewall/miscellaneous/how-zen-works-performance-reliability.md)
* [Zen Firewallのブロックモードと検知モード](/docs/docs-ja/zen-firewall/zen-features/blocking-vs-detection-mode-in-zen-firewall.md)
* [Zen統計を理解する](/docs/docs-ja/zen-firewall/zen-features/understanding-your-zen-statistics.md)
  {% endstep %}
  {% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/zen-firewall/zen-installation-instructions/zen-firewall-for-dotnet/aspnet-framework.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
