顯示具有 IUSR 標籤的文章。 顯示所有文章
顯示具有 IUSR 標籤的文章。 顯示所有文章

2026年1月15日 星期四

[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」的「IUSR」與「應用程式集區識別」覆蓋設定實測

[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」的「IUSR」與「應用程式集區識別」覆蓋設定實測

2026-01-15

ASP.NET WebForm,

IIS 管理員\伺服器\IIS\驗證\動作\開啟功能\匿名驗證\動作\編輯\編輯匿名驗證認證\匿名使用者識別

-----

"IIS/伺服器/站台/網站" 層級的 "匿名驗證" 用預設「IUSR」,可以覆蓋

"IIS/伺服器" 層級的 "匿名驗證" 從「IUSR」改為「應用程式集區識別」設定 ?

ChatGPT

結論:站台/網站層級可以完全覆蓋伺服器層級的設定。

換句話說:

站台或網站層級設為 IUSR,即使伺服器層級改為 應用程式集區識別,該站台/網站仍然使用 IUSR。

註:避免出狀況時,可以讓系統盡快復原運作。

********************************************************************************

2026-01-16補

雖然「網站」層級設定可以覆蓋「伺服器」層級設定,但這個「網站」層級設定,不是儲存在 ASP.NET WebForm 網站根目錄的 Web.Config,而是儲存在 C:\Windows\System32\inetsrv\Config\applicationHost.config 檔案中,

    <location path="WebSite2">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication userName="" />
                </authentication>
            </security>
        </system.webServer>
    </location>

userName="" 空值表示使用 應用程式集區識別 (Application Pool Identity)。

如果是 IUSR,會是:

<anonymousAuthentication enabled="true" userName="IUSR" password="..." />

例如:

<anonymousAuthentication enabled="true" userName="IUSR" />

註:和 SourceCode 的 Web.Config 無關。

********************************************************************************

2026-01-16補

實際測試兩個 ASP.NET WebForm 網站,一個有使用 Microsoft Identity 身分識別機制,一個沒有,似乎登入都正常。

(完)

[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」編輯「匿名驗證」出錯解決

[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」編輯「匿名驗證」出錯解決

2026-01-15

政府組態基準(Government Configuration Baseline,簡稱GCB)

續

[研究]Windows Server 2019 套用 GCB IIS 10.0設定路徑圖解(1)基本設定
https://shaurong.blogspot.com/2025/10/windows-server-2019-gcb-iis-1001.html

[研究]ASP.NET WebForm 用 NuGet 安裝 Microsoft Identity 身分識別機制套件https://shaurong.blogspot.com/2026/01/aspnet-webform-nuget-microsoft-identity.html

項次TWGCB-ID類別原則設定名稱說明設定位置設定路徑GCB設定值
6TWGCB-04-014-0006基本設定匿名使用者識別
  • 這項原則設定決定匿名使用者識別是否設為「應用程式集區識別」
  • 將匿名驗證中之「匿名使用者識別」設定為「應用程式集區識別」,可確保匿名使用者以最小權限之身分執行,可簡化站台管理工作
伺服器IIS 管理員\伺服器\IIS\驗證\動作\開啟功能\匿名驗證\動作\編輯\編輯匿名驗證認證\匿名使用者識別應用程式集區識別



下圖,出錯 


********************************************************************************

【解決】發現網站不小心砍掉,所以 Web.Config 不存在,重新 Deploy 後,成功讀取了。

(完)

相關



[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」從「IUSR」改為「應用程式集區識別」實測

[研究]GCB IIS 10.0 基本設定,「匿名使用者識別」從「IUSR」改為「應用程式集區識別」實測

2026-01-15

政府組態基準(Government Configuration Baseline,簡稱GCB)

續

[研究]Windows Server 2019 套用 GCB IIS 10.0設定路徑圖解(1)基本設定
https://shaurong.blogspot.com/2025/10/windows-server-2019-gcb-iis-1001.html

[研究]ASP.NET WebForm 用 NuGet 安裝 Microsoft Identity 身分識別機制套件https://shaurong.blogspot.com/2026/01/aspnet-webform-nuget-microsoft-identity.html

項次TWGCB-ID類別原則設定名稱說明設定位置設定路徑GCB設定值
6TWGCB-04-014-0006基本設定匿名使用者識別
  • 這項原則設定決定匿名使用者識別是否設為「應用程式集區識別」
  • 將匿名驗證中之「匿名使用者識別」設定為「應用程式集區識別」,可確保匿名使用者以最小權限之身分執行,可簡化站台管理工作
伺服器IIS 管理員\伺服器\IIS\驗證\動作\開啟功能\匿名驗證\動作\編輯\編輯匿名驗證認證\匿名使用者識別應用程式集區識別




註:如果編輯「匿名驗證」出現錯誤,請檢查該網站是否存在

********************************************************************************

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2

********************************************************************************

Default.aspx

<?xml version="1.0" encoding="utf-8"?>
<!--
  如需如何設定 ASP.NET 應用程式的詳細資訊,請前往
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.8" />
    <httpRuntime targetFramework="4.8" />
    <authentication mode="Forms" />
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
    Inherits="WebApplication1.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <h2>IIS GCB 匿名驗證測試</h2>

        <table border="1">
            <tr>
                <th>項目</th>
                <th>值</th>
            </tr>
            <tr>
                <td>User.Identity.IsAuthenticated</td>
                <td><asp:Label ID="lblIsAuthenticated" runat="server" /></td>
            </tr>
            <tr>
                <td>User.Identity.Name</td>
                <td><asp:Label ID="lblUserName" runat="server" /></td>
            </tr>
            <tr>
                <td>HttpContext.Current.User.Identity.AuthenticationType</td>
                <td><asp:Label ID="lblAuthType" runat="server" /></td>
            </tr>
            <tr>
                <td>Request.LogonUserIdentity.Name</td>
                <td><asp:Label ID="lblLogonUser" runat="server" /></td>
            </tr>
        </table>

        <div class="section">
        <h3>Forms Authentication 測試登入</h3>
        帳號:
        <asp:TextBox ID="txtUser" runat="server" />
        <asp:Button ID="btnLogin" runat="server" Text="登入" OnClick="btnLogin_Click" />
        &nbsp;
        <asp:Button ID="btnLogout" runat="server" Text="登出" OnClick="btnLogout_Click" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Web.Security;

namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowIdentity();
        }

        private void ShowIdentity()
        {
            lblIsAuthenticated.Text = User.Identity.IsAuthenticated.ToString();

            lblUserName.Text = string.IsNullOrEmpty(User.Identity.Name)
                ? "(空字串)"
                : User.Identity.Name;

            lblAuthType.Text = string.IsNullOrEmpty(User.Identity.AuthenticationType)
                ? "(null / 空)"
                : User.Identity.AuthenticationType;

            if (Request.LogonUserIdentity != null)
            {
                lblLogonUser.Text = Request.LogonUserIdentity.Name;
            }
            else
            {
                lblLogonUser.Text = "(null)";
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            // 不做帳密驗證,純測試用
            string userName = txtUser.Text.Trim();

            if (!string.IsNullOrEmpty(userName))
            {
                FormsAuthentication.SetAuthCookie(userName, false);
                Response.Redirect(Request.RawUrl);
            }
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Response.Redirect(Request.RawUrl);
        }
    }
}

********************************************************************************

下圖,在 Visual Studio Enterprise 2019 中執行,登入前


下圖,在 Visual Studio Enterprise 2019 中執行,登入後


下圖,未套 GCB,Deploy後,登入前


下圖,未套 GCB,Deploy後,登入後


下圖,套 GCB,Deploy後,登入前

下圖,套 GCB,Deploy後,登入後

Request.LogonUserIdentity.Name 在套用 GCB 前後回傳值可能有變化。

[研究]GCB IIS 10.0「匿名使用者識別」從「IUSR」改為「應用程式集區識別」會否產生問題?

[研究]GCB IIS 10.0「匿名使用者識別」從「IUSR」改為「應用程式集區識別」會否產生問題?(二)

根據這幾篇,影響的東西會很多,有空再繼續研究。

(完)

相關