TrueWatch
立即開始
工作坊

TrueWatch Workshop:eShopOnWeb 部署與監測實作

Angus Lim
·2025年8月6日閱讀時間 2 分鐘
TrueWatch Workshop eShopOnWeb Deployment Instrumentation

概述與範圍

本工作坊將引導您在 Windows IIS 上部署 eShopOnWeb ASP.NET Core 8.0 範例應用程式,並以 TrueWatch 進行埋點。

  • Part A(選用): 全新建置 Windows IIS 與 .NET 環境,並完成應用程式的完整部署。
  • Part B: 為既有 IIS 應用程式完成 TrueWatch 接入與埋點。

該從哪一部分開始?

  • 剛接觸 IIS 與 .NET? 請從 Part A 開始。
  • 應用程式已部署在 IIS 上? 請跳過 Part A,直接前往 Part B。

點擊此處觀看影片教學 — TrueWatch Workshop eShopOnWeb Deployment & Instrumentation

簡介

完成本指南後,您將擁有:

  • 一個由 Windows IIS 代管、已發佈的 ASP.NET Core 8.0 應用程式(eShopOnWeb)

環境先決條件

需求說明
TrueWatch 工作空間請至 https://id1-auth.truewatch.com/businessRegister 註冊
Windows Server(例如 2025)可為 AWS EC2、Parallels、VMware 或實體主機
管理員 RDP 存取權限需對您的 IP 開放 3389 連接埠

Part A – 環境建置與部署

A.1 以系統管理員身分執行 PowerShell,並安裝 Git 與 .NET

# Install Git 
winget install --id Git.Git -e --source winget
 
# Install .NET 8 SDK
winget install --id Microsoft.DotNet.SDK.8 -e
 
# Relaunch PowerShell as Admin and Verify
git --version
dotnet --version

A.2 複製並發佈範例應用程式

git clone https://github.com/dotnet-architecture/eShopOnWeb.git C:\inetpub\wwwroot\eShopOnWeb
 
cd C:\inetpub\wwwroot\eShopOnWeb\src\Web    
 
dotnet publish -c Release -o C:\inetpub\wwwroot\eShopOnWeb\publish

A.3 安裝並註冊 AspNetCoreModuleV2

請從 https://dotnet.microsoft.com/download/dotnet/8.0/runtime 下載「ASP NET Core Runtime 8.0 Hosting Bundle」,並儲存至 C:\Downloads。

# 1. Install silently (as Admin)
Start-Process -FilePath C:\Downloads\dotnet-hosting-8.0.18-win.exe `
  -ArgumentList '/quiet','/norestart' -Wait -Verb RunAs
 
# 2. Verify registration
Import-Module WebAdministration
Get-WebGlobalModule AspNetCoreModuleV2 | Select Name, Image
 
# 3. Restart IIS
iisreset /restart

A.4 建立 logs 目錄並設定 ACL

$pub = 'C:\inetpub\wwwroot\eShopOnWeb\publish'
New-Item -ItemType Directory -Path "$pub\logs" -Force
$pool='eShopOnWebPool'
icacls "$pub\logs" /grant "IIS_IUSRS:(M)" /T

A.5 安裝 IIS Web Server 角色

# Install the full IIS role (Web Server) plus Management tools
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
 
# Now these should show up and be Running (or Stopped if you haven’t started them yet):
Get-Service W3SVC, WAS | Select-Object Name, Status
 
# If they’re stopped, start them:
Start-Service WAS
Start-Service W3SVC

A.6 網站與應用程式集區設定

Install-WindowsFeature Web-Scripting-Tools -IncludeManagementTools
Import-Module WebAdministration
New-WebAppPool $pool
Set-ItemProperty "IIS:\AppPools\$pool" -Name startMode -Value AlwaysRunning
Set-ItemProperty "IIS:\AppPools\$pool" -Name processModel.loadUserProfile -Value True
 
New-Website -Name eShopOnWeb `
  -PhysicalPath $pub `
  -Port 5000 -ApplicationPool $pool

A.7 下載並安裝 SQL Server Express 2022

請前往 https://www.microsoft.com/en-za/sql-server/sql-server-downloads 下載 SQL Server 2022 Express,並選擇「基本」安裝方式。

TrueWatch eshoponweb SQL Server 2022 Express Installation Setup

出現提示時請一併安裝 SSMS。

A.8 設定資料庫

Install-WindowsFeature Web-Scripting-Tools -IncludeManagementTools
Import-Module WebAdministration
New-WebAppPool $pool
Set-ItemProperty "IIS:\AppPools\$pool" -Name startMode -Value AlwaysRunning
Set-ItemProperty "IIS:\AppPools\$pool" -Name processModel.loadUserProfile -Value True
 
New-Website -Name eShopOnWeb `
  -PhysicalPath $pub `
  -Port 5000 -ApplicationPool $pool
  1. 開啟 SQL Server Management Studio(SSMS)

TrueWatch eshoponweb SQL Server Management Studio (SSMS) Setup

  1. 建立 Windows 登入帳號
  • 前往 Security → Logins,按右鍵選擇 New Login…
  • Login name: IIS APPPOOL\eShopOnWebPool
  • 按一下 Save
  1. 建立 CatalogDb 資料庫
  • 選擇 New Query
  • 貼上並執行

CREATE DATABASE [CatalogDb]; GO

TrueWatch eshoponweb CatalogDb

A.9 回收 IIS 並驗證

iisreset /restart
Invoke-WebRequest http://localhost:5000/ -UseBasicParsing

在瀏覽器中開啟 http://localhost:5000/ — 應會顯示 eShopOnWeb 首頁。

Part B – TrueWatch 埋點

B.1 安裝 TrueWatch DataKit Agent

  • 在 TrueWatch 主控台中,前往 Integrations → DataKit → Windows,複製安裝指令碼。
  • 以系統管理員身分在 PowerShell 中執行。
  • 於 Infrastructure → Hosts 下確認主機已出現。

TrueWatch eshoponweb Infrastructure Hosts

TrueWatch eshoponweb Infrastructure Hosts 2

B.2 啟用 DataKit 模組

編輯 C:\Program Files\datakit\conf.d\datakit.conf:

default_enabled_inputs = ["cpu", "disk", "diskio", "mem", "swap", "system", "hostobject", "net", "host_processes", "dk", "statsd", "ddtrace", "windows_event"]

重新啟動 DataKit:

datakit service -R

B.3 為 TrueWatch 更新 web.config

前往 C:\inetpub\wwwroot\eShopOnWeb\publish\web.config 並加入:

<environmentVariable name="DD_AGENT_HOST" value="127.0.0.1" />
<environmentVariable name="DD_TRACE_AGENT_PORT" value="9529" />
<environmentVariable name="DD_RUNTIME_METRICS_ENABLED" value="1" />
<!-- other DD_ vars as needed -->

B.4 啟用 RUM(真實使用者監控)

  1. 在 TrueWatch 中,前往 RUM → Create Application,複製程式碼片段。
  2. 編輯位於 C:\inetpub\wwwroot\eShopOnWeb\src\Web\Views\Shared_Layout.cshtml 的 _Layout.cshtml,並將程式碼片段貼到 head 之下。

TrueWatch eshoponweb Enable RUM 1

TrueWatch eshoponweb Enable RUM 2

B.5 設定 .NET APM 追蹤

  1. 安裝 .NET Tracer MSI(例如 datadog-dotnet-apm-3.21.0-x64.msi)。
  2. 重新啟動 IIS:
net stop was; net start w3svc
  1. 在 TrueWatch APM 中確認已收到追蹤資料

TrueWatch eshoponweb APM

3 項補充說明

程式碼變更後重新發佈

cd C:\inetpub\wwwroot\eShopOnWeb\src\Web
dotnet publish -c Release -o C:\inetpub\wwwroot\eShopOnWeb\publish
Restart-WebAppPool eShopOnWebPool
作者: Angus Lim

Angus Lim is TrueWatch's Presales Solution Architect. He turns TrueWatch product demos into practical, step-by-step guides. His articles are based on the walkthrough videos on TrueWatch's YouTube channel, so engineers can follow along and try the same setup in their own environment.

精選文章

現在就透過 TrueWatch,體驗超越可觀測性的能力。