IIS Manage With AppCmd


  1. 說明
    1. AppCmd Folder
  2. Useful Command
    1. Check Site, Application And Application Pool
    2. Check Application Pool And Worker Process Mapping
    3. Check Reuqests
    4. Disable Upload Folder Script ⭐
    5. Add Site
    6. Add Application Pool (4.0, 2.0, No Managed Code)
    7. Add Application
    8. Delete Site, Application & Application Pool
    9. Assign Application Pool To Application
    10. Enable Anonymous Authentication (匿名驗證)
    11. Swithc Windows Authentication Providers (NTLM / Negotiate)
    12. Custom Header
    13. Setting Default Document
    14. Backup and Restore IIS Settings
    15. HTTPS Binding
    16. Application Pool Always Running
  3. aspnet_regiis
  4. 參考資料
  5. 相關連結

筆記如何使用 AppCmd 進行 IIS 的站台管理、部署與各項組態設定,藉由活用 AppCmd 精進 IIS 的管理之道。

logo

說明

管理目標 說明
Site 虛擬站台
App 應用程式
Vdir 虛擬目錄
Apppool 應用程式集區
Config 組態設定
Backup 伺服器組態備份
WP Worker Process
Requests Active HTTP Request
Module Server Module
Trace Sever Trace Log

AppCmd Folder

IIS Express

cd C:\Program Files\IIS Express

IIS

cd %systemroot%\system32\inetsrv\

Useful Command

Check Site, Application And Application Pool

appcmd list site
appcmd list app
appcmd list apppool

Check Application Pool And Worker Process Mapping

appcmd list wps

Check Reuqests

appcmd list requests

Disable Upload Folder Script ⭐

appcmd set config "Default Web Site/MyApp/Upload" /section:system.webServer/handlers /accessPolicy:Read /commit:url
commit 位置 範例
site 寫在整個 Site 層級 D:\Websites\
app 寫在 ApplicationHost 層級 D:\Websites\App1
url 寫在特定路徑 D:\Websites\App1\Upload

Add Site

appcmd add site /name:MySite /bindings:http://*:80 /physicalpath:"D:\Websites"

Add Application Pool (4.0, 2.0, No Managed Code)

appcmd add apppool /name:MyAppPool /managedRuntimeVersion:v4.0
appcmd add apppool /name:MyAppPool /managedRuntimeVersion:v2.0

REM No Managed Code
appcmd add apppool /name:MyAppPool /managedRuntimeVersion:""

Add Application

appcmd add app /site.name:"MySite" /path:/MyApp /physicalpath:"D:\Websites\MyApp"

Delete Site, Application & Application Pool

appcmd delete site "MySite"
appcmd delete app "MySite/MyApp"
appcmd delete apppool MyAppPool

Assign Application Pool To Application

appcmd set app "MySite/MyApp" /applicationpool:MyAppPool

Enable Anonymous Authentication (匿名驗證)

REM Anonymous Authentication
appcmd set config "MySite/MyApp" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost

REM Windows Authentication
appcmd.exe set config "MySite/MyApp" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost

Swithc Windows Authentication Providers (NTLM / Negotiate)

REM Clear Provider List First
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /~providers /commit:apphost

REM NTLM
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /-providers.[value='NTLM'] /commit:apphost

REM Negotiate
appcmd set config MySite/MyApp -section:system.webServer/security/authentication/windowsAuthentication /+providers.[value='Negotiate'] /commit:apphost

Custom Header

appcmd  set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-Content-Type-Options',value='nosniff'] /commit:apphost
appcmd set config MySite -section:system.webServer/httpProtocol /+customHeaders.[name='X-UA-Compatible',value='IE=EmulateIE7'] /commit:apphost

Setting Default Document

appcmd set config "MySite/MyApp" /section:defaultDocument /+files.[value='hello.aspx']

Backup and Restore IIS Settings

appcmd add backup MyBackup
appcmd restore backup MyBackup

IIS Backup & Restore Sites & Application Pools 備份與還原 IIS 站台與應用程式集區

HTTPS Binding

appcmd set site /site.name:"MyApp" /+bindings.[protocol='https',bindingInformation='*:443:MySSLCertificate']

Application Pool Always Running

set apppool /apppool.name:AppPoolName /startMode:AlwaysRunning
set apppool /apppool.name:AppPoolName /autoStart:true
set config /section:applicationPools /[name='AppPoolName'].processModel.idleTimeoutAction:Suspend

aspnet_regiis

加密 web.config 連線字串密碼的方式,使用 pef

aspnet_regiis.exe -pef "connectionStrings" "D:\Sites\MyApplication"

解密 web.config 連線字串密碼的方式,,使用 pdf

aspnet_regiis.exe -pdf "connectionStrings" "D:\Sites\MyApplication"

IIS Encrypt Web.config (Single Server, AppSettings, Web Farm)

參考資料

Getting Started with AppCmd.exe | learn.microsoft

Appcmd Most Common Commands | gist by Mike Mahon

相關連結

IIS 筆記整理

IIS 網頁伺服器的安全設定 (IIS Security Configuration)