[研究]IIS 10.0 GCB,實測 Web.Config 多甚麼 - forms cookieless="UseCookies"
2025-01-16
IIS 10.0 套用 GCB 後,有些會變更現有 Web.Config 設定,要回頭改 Source Code,否則下次 Deploy 後,GCB 設定會被覆蓋消失。
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2
********************************************************************************
兩個不同系統套用 IIS 10.0 GCB 後 Web.Config
<authentication mode="None">
<forms cookieless="UseCookies" />
</authentication>
|
<authentication mode="Windows">
<forms cookieless="UseCookies" requireSSL="true" />
</authentication>
|
相關 No.9、No.18,分別
IIS管理員\伺服器\站台\網站\管理\設定編輯器\動作\開啟功能\區段\system.web\authentication\forms\cookieless
IIS管理員\伺服器\站台\網站\管理\設定編輯器\動作\開啟功能\區段\system.web\sessionState\cookieless
No.9 預設「UseDeviceProfile」,GCB建議 UseCookies
No.18 預設值和GCB建議 UseCookies,不會寫 Web.Config
********************************************************************************
No.9 套用後
<configuration>
<system.web>
<compilation targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
<machineKey validation="HMACSHA256" />
<authentication>
<forms cookieless="UseCookies" />
</authentication>
</system.web>
</configuration>
|
********************************************************************************
| 項次 | TWGCB-ID | 類別 | 原則設定名稱 | 說明 | 設定位置 | 設定路徑 | GCB設定值 |
| 9 | TWGCB-04-014-0009 | 設定驗證與授權 | 表單驗證Cookie 模式 |
| 站台 | IIS 管理員\伺服器\站台\網站\管理\設定編輯器\動作\開啟功能\區段\system.web\authentication\forms\cookieless | UseCookies |
下圖,cookieless預設值是 UseDeviceProfile
改成 UseCookies後,套用,Web.Config 結果如下
[研究]GCB,IIS,「表單驗證Cookie 模式」從預設值 UseDeviceProfile 改為 GCB 建議值 UseCookies 的影響?
主要影響老舊瀏覽器
[研究]GCB,IIS,「表單驗證Cookie 模式」從預設值 UseDeviceProfile 改為 GCB 建議值 UseCookies後那些套件功能會異常?
https://shaurong.blogspot.com/2025/11/gcbiiscookie-usedeviceprofile-gcb.html
Microsoft.AspNet.FriendlyUrls、ASP.NET Identity、Microsoft.Owin.Security.Cookies、jQuery、Bootstrap.Datepicker、js-cookie、vue 可能異常。
Microsoft.AspNet.FriendlyUrls、ASP.NET Identity、Microsoft.Owin.Security.Cookies、jQuery、Bootstrap.Datepicker、js-cookie、vue 可能異常。
實際檢視某 ASP.NET WebForm 真實系統,該網站cookieless設定值是 UseDeviceProfile。
GCB建議是 UseCookies。
"可能" 會導致某些套件無法正常運作。
********************************************************************************
FormsAuthenticationConfiguration.Cookieless 屬性
AuthenticationMode 列舉
| <authentication>的mode值 | 說明 |
| None | 不指定驗證。 |
| Windows | 指定 Windows 當做驗證模式。 當使用網際網路資訊服務 (IIS) 驗證方法 (基本、摘要、整合式 Windows (NTLM/Kerberos) 或憑證) 時,會套用這個模式。 |
| Passport | 指定 Microsoft Passport 當做驗證模式。 |
| Forms | 將 ASP.NET 表單式驗證指定為驗證模式。 |
效果表
<authentication mode> | <forms> 標籤是否有效 | 使用情境 | 行為 / 備註 | 建議環境設定 |
|---|---|---|---|---|
Forms (預設 <authentication> 未指定 mode 也是 Forms) | ✅ 有效 | 傳統 WebForm 登入系統 | 使用 <forms> 的 cookie 或 URL 保存驗證票 (FormsAuthenticationTicket);支援 cookieless、loginUrl、timeout 等屬性 | 開發 / 測試 / 正式:如果使用自訂登入系統(Forms Authentication) |
| Windows | ❌ 無效 | 內網 / AD 驗證 | IIS 控制 Windows 認證(NTLM / Kerberos);忽略 <forms> 設定;登入使用者由 Windows 帳號提供 | 開發 / 測試內網可用;正式機公開網不建議 |
| None | ❌ 無效 | 不使用 ASP.NET 原生認證 | 完全不啟用 FormsAuthenticationModule;若使用 Microsoft Identity (OWIN) 或其他自訂認證,需要 mode="None" | 開發 / 測試可快速跳過登入;正式機使用 Microsoft Identity/Owin cookie |
實際測試套用了,目前沒看到問題。
(完)
相關


沒有留言:
張貼留言