顯示具有 .NET Framework 標籤的文章。 顯示所有文章
顯示具有 .NET Framework 標籤的文章。 顯示所有文章

2025年12月2日 星期二

[研究]ASP.NET WebForm 用 IIS GUI 判斷使用的 .NET Framework 版本? 32 bits 或 64位元?

[研究]ASP.NET WebForm 用 IIS GUI 判斷使用的 .NET Framework 版本? 32 bits 或 64位元?

2025-12-02

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

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

ChatGPT

1️⃣ 判斷應用程式使用的 .NET Framework 版本

  1. 打開 IIS 管理員。
  2. 左側選擇你的 網站 或 應用程式集區 (Application Pool)。
  3. 若要看整個 AppPool 使用

    .NET Framework 版本:

    • 選擇 應用程式集區 → 找到你的 AppPool → 右鍵 → 進階設定 (Advanced Settings...)。
    • 找到 .NET CLR 版本 (.NET CLR Version) 欄位:
      • v4.0 → 代表使用 .NET Framework 4.x(包括 4.5, 4.6, 4.7, 4.8)。
      • v2.0 → 代表使用 .NET Framework 2.0/3.0/3.5。

注意:IIS GUI 只能顯示 CLR 版本,而不能精確顯示小版本(如 4.7.2 或 4.8),要看精確版本仍需程式判斷。


2️⃣ 判斷應用程式集區是 32-bit 或 64-bit

  1. 同樣在 應用程式集區 → 選擇你的 AppPool → 右鍵 → 進階設定。
  2. 找到 啟用 32 位元應用程式 (Enable 32-Bit Applications):

    • True → 應用程式在 32-bit 模式 執行,即使 OS 是 64-bit。
    • False → 應用程式跟隨 OS 執行:
      • OS 64-bit → 應用程式 64-bit。
      • OS 32-bit → 應用程式 32-bit。


3️⃣ 判斷 OS 位元數(IIS Server 環境)

在 IIS GUI 沒有直接顯示 OS 位元數,但可以透過:

伺服器管理員 (Server Manager) → 系統資訊 查看作業系統版本和位元數。

或者在 命令提示字元 輸入:

systeminfo | findstr /B /C:"OS 名稱" /C:"系統類型"   

會顯示:

系統類型: x64-based PC → 64-bit OS

系統類型: x86-based PC → 32-bit OS

🔹 小結

判斷項目 IIS GUI 路徑 說明
.NET Framework 版本 AppPool → Advanced Settings → .NET CLR Version v2.0 / v4.0
應用程式位元數 AppPool → Advanced Settings → Enable 32-Bit Applications True = 32-bit, False = 隨 OS
OS 位元數 系統資訊或 systeminfo 指令 x64 / x86


(完)

相關

2024年11月7日 星期四

[研究]Windows Server 2019 不能安裝 Microsoft .NET Framework 4.8.1

[研究]Windows Server 2019 不能安裝 Microsoft .NET Framework 4.8.1

2024-11-07

下載 .NET Framework
https://dotnet.microsoft.com/zh-tw/download/dotnet-framework

Windows Server 2019 安裝 Microsoft .NET Framework 4.8.1 出現錯誤:

這個作業系統不支援 .NET Framework 4.8.1。

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

查了一下

.NET Framework 系統需求
https://learn.microsoft.com/zh-tw/dotnet/framework/get-started/system-requirements

.NET Framework system requirements
https://learn.microsoft.com/en-us/dotnet/framework/get-started/system-requirements



(完)

2024年3月19日 星期二

[研究]C#,顯示「帳戶原則」(「密碼原則」、「帳戶鎖定原則」)結果

[研究]C#,顯示「帳戶原則」(「密碼原則」、「帳戶鎖定原則」)結果

2024-03-19

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

密碼原則

  • 使用可還原的加密來存放密碼
  • 密碼必須符合複雜性需求
  • 密碼最短使用期限
  • 密碼最長使用期限
  • 強制執行密碼歷程記錄
  • 最小密碼長度

已啟用 ? 已停用?  尚未定義 ?


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

WinForm 程式

using System;
using System.Windows.Forms;

namespace ServerHealthCheckWindowsFormsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                richTextBox1.AppendText("rsop.msc\n");
                richTextBox1.AppendText("電腦設定\\Windows設定\\安全性設定\\帳戶原則\\密碼原則\n\n");

                #region === 使用可還原的加密來存放密碼 ===
                string registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
                object clearTextPasswordValue = Microsoft.Win32.Registry.GetValue(registryPath, "ClearTextPassword", null);
                if (clearTextPasswordValue != null)
                {
                    int value = Convert.ToInt32(clearTextPasswordValue);
                    if (value == 1)
                    {
                        richTextBox1.AppendText("使用可還原的加密來存放密碼:已啟用\n");
                    }
                    else
                    {
                        richTextBox1.AppendText("使用可還原的加密來存放密碼:已停用\n");
                    }
                    //精簡寫法
                    //richTextBox1.AppendText("使用可還原的加密來存放密碼:" + ((Boolean)clearTextPasswordValue ? "已啟用" : "已停用") + "\n");
                }
                else
                {
                    
                    richTextBox1.AppendText("使用可還原的加密來存放密碼:尚未定義\n");
                }
//精簡寫法 (尚未測試)
richTextBox1.AppendText($"使用可還原的加密來存放密碼:{(clearTextPasswordValue != null && (int)clearTextPasswordValue == 1 ? "
已啟用 " : (clearTextPasswordValue != null && (int)clearTextPasswordValue != 1 ? " 已停用 " : " 尚未定義 "))}\n"); #endregion === 使用可還原的加密來存放密碼 === #region === 密碼必須符合複雜性需求 === registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; // Read the value of the "PasswordComplexity" registry key object passwordComplexityValue = Microsoft.Win32.Registry.GetValue(registryPath, "PasswordComplexity", null); if (passwordComplexityValue != null) { richTextBox1.AppendText("密碼必須符合複雜性需求:" + ((Boolean)passwordComplexityValue ? "已啟用" : "已停用") + "\n"); } else { richTextBox1.AppendText("密碼必須符合複雜性需求:尚未定義\n"); } #endregion === 密碼必須符合複雜性需求 === #region === 密碼最短使用期限 === registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; object minimumPasswordAgeValue = Microsoft.Win32.Registry.GetValue(registryPath, "MinimumPasswordAge", null); if (minimumPasswordAgeValue != null) { int valueInSeconds = Convert.ToInt32(minimumPasswordAgeValue); int valueInDays = valueInSeconds / (60 * 60 * 24); // Convert to number of days richTextBox1.AppendText("密碼最短使用期限:" + valueInDays.ToString() + " 天\n"); } else { richTextBox1.AppendText("密碼最短使用期限:尚未定義\n"); } #endregion === 密碼最短使用期限 === #region === 密碼最長使用期限=== registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; object maximumPasswordAgeValue = Microsoft.Win32.Registry.GetValue(registryPath, "MaximumPasswordAge", null); if (maximumPasswordAgeValue != null) { int valueInSeconds = Convert.ToInt32(maximumPasswordAgeValue); int valueInDays = valueInSeconds / (60 * 60 * 24); // Convert to number of days richTextBox1.AppendText("密碼最長使用期限:" + valueInDays.ToString() + " 天\n"); } else { richTextBox1.AppendText("密碼最長使用期限:尚未定義\n"); } #endregion === 密碼最長使用期限=== #region === 密碼最短使用期限、密碼最長使用期限=== // Console 寫法 //object minimumPasswordAgeValue = Microsoft.Win32.Registry.GetValue(registryPath, "MinimumPasswordAge", null); //object maximumPasswordAgeValue = Microsoft.Win32.Registry.GetValue(registryPath, "MaximumPasswordAge", null); string minimumPasswordAgeStatus = minimumPasswordAgeValue != null ? "已設定" : "尚未設定"; string minimumPasswordAgeValueText = minimumPasswordAgeValue != null ? $"(設定值:{minimumPasswordAgeValue})" : ""; string maximumPasswordAgeStatus = maximumPasswordAgeValue != null ? "已設定" : "尚未設定"; string maximumPasswordAgeValueText = maximumPasswordAgeValue != null ? $"(設定值:{maximumPasswordAgeValue})" : ""; Console.WriteLine("密碼最短使用期限:{0} {1}", minimumPasswordAgeStatus, minimumPasswordAgeValueText); Console.WriteLine("密碼最長使用期限:{0} {1}", maximumPasswordAgeStatus, maximumPasswordAgeValueText); #endregion === 密碼最短使用期限、密碼最長使用期限=== #region === 強制執行密碼歷程記錄 === registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; object passwordHistorySizeValue = Microsoft.Win32.Registry.GetValue(registryPath, "PasswordHistorySize", null); if (passwordHistorySizeValue != null) { int value = Convert.ToInt32(passwordHistorySizeValue); if (value > 0) { richTextBox1.AppendText("強制執行密碼歷程記錄:已停用\n"); richTextBox1.AppendText("密碼歷程記錄秒數:" + value.ToString() + "\n"); } else { richTextBox1.AppendText("強制執行密碼歷程記錄:已停用\n"); } } else { richTextBox1.AppendText("強制執行密碼歷程記錄:尚未定義\n"); } #endregion === 強制執行密碼歷程記錄 === #region === 最小密碼長度 === registryPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; object minimumPasswordLengthValue = Microsoft.Win32.Registry.GetValue(registryPath, "MinimumPasswordLength", null); if (minimumPasswordLengthValue != null) { int value = Convert.ToInt32(minimumPasswordLengthValue); Console.WriteLine("Minimum password length: {0}", value); richTextBox1.AppendText("最小密碼長度:" + value.ToString() + "\n"); } else { richTextBox1.AppendText("最小密碼長度:尚未定義\n"); } #endregion === 最小密碼長度 === } catch (Exception ex) { richTextBox1.AppendText("發生異常:" + ex.Message.ToString()); } // Console 增加 //finally //{ // Console.WriteLine("按下任意鍵退出..."); // Console.ReadKey(); //} } } }

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

【電腦設定\Windows設定\安全性設定\帳戶原則\帳戶鎖定原則】


重設帳戶鎖定計數器的時間間隔

帳戶鎖定期間

帳戶鎖定閾值

已啟用 ? 已停用? 尚未設定 ? 值 ? 繁體中文

using Microsoft.Win32;
using System;
using System.Windows.Forms;

namespace AccountLockoutPolicyExample
{
     public partial class MainForm : Form
     {
         public MainForm()
         {
             InitializeComponent();
         }

         private void MainForm_Load(object sender, EventArgs e)
         {
             try
             {
                 // 本機的登錄路徑
                 string registryPath = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon";

                 // 讀取 "ResetLockoutCount" 註冊表鍵的值
                 object resetLockoutCountValue = Registry.GetValue($"HKEY_LOCAL_MACHINE\\{registryPath}", "ResetLockoutCount", null);

                 // 檢查策略的狀態
                 string resetLockoutCountStatus = GetPolicyStatus(resetLockoutCountValue);

                 // 讀取 "LockoutDuration" 註冊表鍵的值
                 object lockoutDurationValue = Registry.GetValue($"HKEY_LOCAL_MACHINE\\{registryPath}", "LockoutDuration", null);
                 string lockoutDurationStatus = GetPolicyStatus(lockoutDurationValue);

                 // 讀取 "LockoutThreshold" 註冊表鍵的值
                 object lockoutThresholdValue = Registry.GetValue($"HKEY_LOCAL_MACHINE\\{registryPath}", "LockoutThreshold", null);
                 string lockoutThresholdStatus = GetPolicyStatus(lockoutThresholdValue);

                 // 顯示結果
                 richTextBox.Text = $"重設帳戶鎖定計數器的時間間隔:{resetLockoutCountStatus}\n" +
                                     $"帳戶鎖定期間:{lockoutDurationStatus}\n" +
                                     $"帳戶鎖定閾值:{lockoutThresholdStatus}";
             }
             catch (Exception ex)
             {
                 richTextBox.Text = $"發生例外狀況:{ex.Message}";
             }
         }

         private string GetPolicyStatus(object policyValue)
         {
             if (policyValue != null)
             {
                 return $"已啟用 (值:{policyValue})";
             }
             else
             {
                 return "尚未設定";
             }
         }
     }
}


(完)

相關

2023年12月30日 星期六

[研究]建立ASP.NET WebForm WebSite 方案於 Visual Studio 2019 / 2022

[研究]建立ASP.NET WebForm WebSite 方案於 Visual Studio 2019 / 2022

2023-12-30

早期 Visual Studio ( Visual Studio 2008 ? ) 提供 ASP.NET WebForm (.NET Framework) 範本 (template),又分 WebSite 和 WebApplication 兩種範本;較新的 Visual Studio 不再提供不需要編譯的  ASP.NET Empty Web Site Template (範本),僅留需要編譯的 Web Application 範本。

雖然無法直接使用 ASP.NET Empty Web Site Template 建立方案 (Solution) / 專案 (Project),但仍有辦法建立 ASP.NET Empty Web Site Template 方案。 
















(完)

2022年9月8日 星期四

[研究] .NET Framework 4.8.1

[研究] .NET Framework 4.8.1 

2022-09-07

.NET Framework 4.8.1 於 2022-08-09 釋出

Announcing .NET Framework 4.8.1 - .NET Blog
https://devblogs.microsoft.com/dotnet/announcing-dotnet-framework-481/

Download .NET Framework | Free official downloads
https://dotnet.microsoft.com/en-us/download/dotnet-framework

Download .NET Framework 4.8.1 | Free official downloads
https://dotnet.microsoft.com/en-us/download/dotnet-framework/net481

包含

  • .NET Framework 4.8.1 Runtime
  • .NET Framework 4.8.1 Runtime - 中文 (繁體) Language packs
  • .NET Framework 4.8.1 Developer Pack
  • .NET Framework 4.8.1 Developer Pack - 中文 (繁體) Language packs

受支援 Windows 版本

  • Windows Client 版本: Windows 11, Windows 10 version 21H2, Windows 10 version 21H1, Windows 10 version 20H2
  • Windows Server 版本: Windows Server 2022

(完)