2021年8月28日 星期六

SQL Server 2012 Native Client - QFE才支援TLS 1.2

某次SQL Server伺服器作業系統關閉TLS 1.0和1.1之後,AP程式連DB有問題,後來發現是要安裝新版的SQL Server 2012 Native Client - QFE。原本是安裝舊版的11.0.2100.60(在2012年發佈的)。安裝後需要重新啟動伺服器。

下載Microsoft® SQL Server® 2012 Native Client - QFE (支援TLS 1.2)
https://www.microsoft.com/en-us/download/details.aspx?id=50402

Version:
11.0.7001.0

Date Published:
1/19/2018



升級成新版可以在AP伺服器建立一個 .udl檔案測試和資料庫連線,可參考以下網址
https://success.trendmicro.com/solution/1118930-using-tlsv1-1-or-tlsv1-2-for-communication-between-mssql-server-and-officescan

 
KB3135244 - TLS 1.2 support for Microsoft SQL Server(必看!)
https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe

 
 

sqlncli.msi安裝程式資訊(
QFE版,支援TLS1.2)



sqlncli.msi安裝程式資訊(舊版,不支援TLS1.2)
 

 
 
AP程式的錯誤訊息(Crystal Report版本是11.5,AP伺服器安裝舊版sqlncli.msi,DB伺服器已關閉TLS 1.0和1.1):

System.Runtime.InteropServices.COMException (0x8004100F): Logon failed.

Details:  [Database Vendor Code: 10054 ]

Logon failed.

Details:  [Database Vendor Code: 10054 ]

Error in File C:\Windows\TEMP\XXXXX.rpt:

Unable to connect: incorrect log on parameters.

Details:  [Database Vendor Code: 10054 ]

   at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.SetTableLocation(ISCRTable CurTable, ISCRTable NewTable)

   at CrystalDecisions.CrystalReports.Engine.Table.set_Location(String value)
 
 
 
Event Log的錯誤訊息:
 
 
 


如果有用到ODBC Driver 11 for SQL Server(msodbcsql.msi)也需要新版才支援TLS1.2
<最新版已經出到17)
https://docs.microsoft.com/zh-tw/sharepoint/security-for-sharepoint-server/enable-tls-1-1-and-tls-1-2-support-in-sharepoint-server-2016

1.1 - 安裝 ODBC Driver 11 for SQL Server 的 TLS 1.2 支援更新

ODBC Driver 11 for SQL Server (適用於 SQL Server 的 ODBC 驅動程式 11) 預設不支援 TLS 1.1 或 TLS 1.2。您必須安裝 ODBC Driver 11 for SQL Server 的 TLS 1.2 支援更新。

CheckClientUpdates.ps1
The PowerShell Script currently supports the following:

Check if SQL Server Native Client can support TLS 1.2
Check if Microsoft ODBC Driver for SQL Server can support TLS 1.2 This script is restricted to work on x64 and x86 platforms


在AP伺服器上檢測SQL Server資料庫驅動程式是否支援TLS 1.2?
支援TLS 1.2


不支援TLS 1.2

 
 
 
 
以下文章參考用,和升級TLS 1.2無關
https://docs.microsoft.com/en-us/sql/connect/oledb/oledb-driver-for-sql-server?view=sql-server-ver15

Different generations of OLE DB Drivers

There are three distinct generations of Microsoft OLE DB providers for SQL Server.

1. Microsoft OLE DB Provider for SQL Server (SQLOLEDB)

The Microsoft OLE DB Provider for SQL Server (SQLOLEDB) still ships as part of Windows Data Access Components. It is not maintained anymore and it is not recommended to use this driver for new development.

2. SQL Server Native Client (SNAC)

Starting in SQL Server 2005 (9.x), the SQL Server Native Client (SNAC) includes an OLE DB provider interface (SQLNCLI) and is the OLE DB provider that shipped with SQL Server 2005 (9.x) through SQL Server 2012 (11.x).

It was announced as deprecated in 2011 and it is not recommended to use this driver for new development. For more information about the SNAC lifecycle and available downloads, refer to SNAC lifecycle explained.

3. Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL)

OLE DB was undeprecated and released in 2018.

The new OLE DB provider is called the Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL). The new provider will be updated with the most recent server features going forward.

 Note

To use the new Microsoft OLE DB Driver for SQL Server in existing applications, you should plan to convert your connection strings from SQLOLEDB or SQLNCLI, to MSOLEDBSQL.

 

KB 4486153:Windows 10和 Windows Server 2019的.NET Framework 4.8

https://support.microsoft.com/zh-tw/topic/%E9%81%A9%E7%94%A8%E6%96%BC-x64-%E6%9B%B4%E6%96%B0%E4%B9%8B-windows-server-2019-windows-10-1709-%E7%89%88%E5%92%8C-windows-10-1803-%E7%89%88%E5%92%8C-windows-10-1809-%E7%89%88%E7%9A%84-microsoft-net-framework-4-8-9e61c44e-08d2-f20d-c890-9ed873d9dba0

 簡介

本文介紹了 Windows 10、版本 1709、Windows 10、版本 1803、Windows Server、版本 1803、Windows 10、版本 1809 和 Windows Server、版本 1809 和 Windows Server 2019 上的 Microsoft .NET Framework 4.8 的更新。

請注意: 從 2020 年 1 月 14 日開始,.NET Framework 4.8 已使用最新的服務更新重新整理。 除了 服務修正程式,2019 年 8 月 13 日發行的 Windows Update 中 , .NET Framework 4.8 產品中沒有任何變更。 如果您已下載並 安裝 8 月發行的更新,則不需要安裝此更新, 否則,請安裝此更新以收到最新的產品位元。

 

https://support.microsoft.com/zh-tw/topic/%E7%94%A8%E6%96%BC-windows-%E7%9A%84-microsoft-net-framework-4-8-%E9%9B%A2%E7%B7%9A%E5%AE%89%E8%A3%9D%E7%A8%8B%E5%BC%8F-9d23f658-3b97-68ab-d013-aa3c3e7495e0

安裝此套件時,將根據您的作業系統安装以下套件或更新:

  • 在 Windows 7 SP1 和 Windows Server 2008 R2 SP1 中,Microsoft.NET Framework 4.8.1 (KB4503548) 在「控制台」下的「程式和功能」中列為已安裝產品。

  • 在 Windows Server 2012 中,Microsoft Windows 的更新 (KB4486081) 位於控制台下的「已安裝更新」中。 在 Windows 8.1 或 Windows Server 2012 R2 中,Microsoft Windows 的更新 (KB4486105) 位於控制台的「已安装更新」當中。

  • 在 Windows 8.1 或 Windows Server 2012 R2 中,Microsoft Windows 的更新 (KB4486105) 位於控制台的「已安装更新」當中。

  • 在 Windows 10 周年更新(版本 1607)、Windows 10 建立者更新 (版本 1703) 和 Windows Sever 2016 中,它在控制台下的「已安裝更新」中被列為 Microsoft Windows 更新 (KB4486129)。

  • 在 Windows 10 秋季建立者的更新版本 1709、Windows 2018 年 4 月 10 日更新 (版本 1803)、Windows 2018 2018 更新 (版本 1809) 和 Windows Server 2019 中,它在控制台的「已安裝更新」下被列為「微軟 Windows 更新 」(KB4486153)。

2020年6月22日 星期一

2020年6月21日 星期日

製作Visual Studio 2019專業版離線安裝檔

因為公司屬於企業組織,根據授權條款不能在公司使用Community版本,但公司連網際網路有管制,需要製作離線安裝檔。

事先到https://docs.microsoft.com/zh-tw/visualstudio/install/create-an-offline-installation-of-visual-studio?view=vs-2019下載vs_professional.exe

離線安裝檔包含.NET web和.NET desktop development和Office development(繁中和英文):
請事先在D磁碟機建立vs2019pro資料夾
使用命令提示字元執行以下指令
vs_professional.exe  --layout D:\vs2019pro --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio --add Microsoft.VisualStudio.Workload.Office --includeOptional --lang en-US zh-TW



參考資料:
https://docs.microsoft.com/zh-tw/visualstudio/install/create-an-offline-installation-of-visual-studio?view=vs-2019

https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/create-an-offline-installation-of-visual-studio.md


For .NET web and .NET desktop development, run:
vs_professional.exe --layout D:\vs2019pro --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio --includeOptional --lang en-US zh-TW


To create a complete local layout with all features (this will take a long time—we have lots of features!), run:
vs_professional.exe --layout D:\vs2019pro --lang en-US zh-TW


For .NET desktop and Office development, run:
vs_professional.exe --layout D:\vs2019pro --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.Office --includeOptional --lang en-US zh-TW

2020年6月13日 星期六

BinaryFormatter()搭配SerializationBinder類別驗證許可還原序列化的類別

避免Unsafe Deserialization弱點



https://topic.alibabacloud.com/tc/a/-net-c--pilot-type-in-deserialization-using-serializationbinder_1_31_32345296.html

//SerializationBinder的執行類
class ConversionBinder : SerializationBinder
{
    public override Type BindToType(string assemblyName, string typeName)
    {
        //篩選Person類型
        //判斷是否是Person類型,如果是返回Person_ver2
        var curAssName = typeof(Program).Assembly.FullName;
        var person1 = typeof(Person).FullName;
        string finalType = typeName;
        if (assemblyName == curAssName && typeName == person1)
            finalType = typeof(Person_ver2).FullName;
        return Type.GetType(finalType + "," + assemblyName);
    }
}

    var bf = new BinaryFormatter();
    //設定自訂的SerializationBinder對象
    bf.Binder = new ConversionBinder();
    //序列化Person
    bf.Serialize(ms, p1);
ref:
https://www.slideshare.net/MSbluehat/dangerous-contents-securing-net-deserialization?from_action=save
p.27

https://owasp.org/www-community/vulnerabilities/Deserialization_of_untrusted_data

2020年6月4日 星期四

NET Core 2.1開始Identity UI被包進Razor Class Library

NET Core 2.1開始Identity UI被包進Razor Class Library
如果需要Identity Core的cshtml修改可以參考
指令產生
先安裝ASP.NET Core scaffolding engine
指令dotnet tool install -g dotnet-aspnet-codegenerator

指令dotnet aspnet-codegenerator identity 
需要先用NuGet安裝以下套件(用Visual Studio的Scaffolding Item會自動安裝)
Microsoft.VisualStudio.Web.CodeGeneration.Design 
Microsoft.AspNetCore.Identity.UI
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer

2020年6月3日 星期三

error CS0234: 命名空間 'Microsoft.AspNetCore.Identity' 中沒有類型或命名空間名稱 'UI' (是否遺漏了組件參考?)

因為Microsoft.AspNetCore.Identity.UI 3.1.4 只支援.NET Core 3.1以上
https://www.nuget.org/packages/Microsoft.AspNetCore.Identity.UI
所以要把專案升級到.NET Core 3.1以上


obj\Debug\netcoreapp3.0\SkillTreeRazorPageBlogSample.AssemblyInfo.cs(14,42): error CS0234: 命名空間 'Microsoft.AspNetCore.Identity' 中沒有類型或命名空間名稱 'UI' (是否遺漏了組件參考?) [D:\temptest\SkillTreeRazorPageBlogSample.csproj]
    0 個警告
    1 個錯誤

經過時間 00:00:03.72
RunTime 00:00:14.95

2020年6月1日 星期一

TagMode.StartTagAndEndTag

https://docs.microsoft.com/zh-tw/aspnet/core/mvc/views/tag-helpers/authoring?view=aspnetcore-3.1

You can use the following markup with a closing tag and remove the line with TagMode.StartTagAndEndTag in the tag helper:
<website-information info="webContext" >
</website-information>



https://whosnailaspnetcoredocs.readthedocs.io/ko/latest/mvc/views/tag-helpers/authoring.html
[HtmlTargetElement("email", TagStructure = TagStructure.WithoutEndTag)] 
public class EmailVoidTagHelper : TagHelper
{
    private const string EmailDomain = "contoso.com";
    // Code removed for brevity
 
 ref:
https://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-4_3_6_2-tag-helpers-authoring.html

2020年5月23日 星期六

libphonenumber-csharp

https://github.com/twcclegg/libphonenumber-csharp

檢查電話號碼格式是否正確
還會顯示分類:FIXED_LINE、MOBILE、VOIP(070門號)、TOLL_FREE(080門號)

DEMO:
https://libphonenumber.appspot.com

Java原版:
https://github.com/google/libphonenumber

ref:
https://www.twilio.com/blog/validating-phone-numbers-effectively-with-c-and-the-net-frameworks

https://medium.com/frochu/libphonenumber-example-app-f60680faa599 

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor' while attempting to activate

 寫.NET Core遇到Unable to resolve service for type通常是忘記註冊物件給DI容器

 Startup.cs的ConfigureServices(IServiceCollection services)加入以下這一行
            //TagsHelper使用
            services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();


錯誤訊息:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor' while attempting to activate

IList和IEnumerable的比較

自己通常使用IEnumerable<T>
但還是會有需要用到IList<T>的時候

http://trufflepenne.blogspot.com/2013/04/ilistienumerable.html

https://stackoverflow.com/questions/376708/ilist-vs-ienumerable-for-collections-on-entities

2020年2月9日 星期日

C#和Java的泛型差異

http://www.jprl.com/Blog/archive/development/2007/Aug-31.html
雖然很舊的文章,但是很詳細的比較了C#和Java泛型的差異

最近在看Essential C# 6這本書,第11章(C# 7是在第12章)有提到Java和C#泛型機制的不同。搜尋了一些資料,小弟我大致整理如下,歡迎先進補充指正,謝謝

JDK 5加入泛型,為了避免修改JVM規格影響向下相容,是在編譯器實作泛型(不是在JVM實作),另外Java的泛型不支援Primitive Type(等同C#的Value Type)
Java採用Code Sharing實作,對每一個泛型類或泛型方法只會生成一份object code(byte code),Java compiler透過type erasure實作,也導致無法在runtime時期取得泛型類或泛型方法的實際型別
C#和C++ Template採用Code Specialization實作,對每一個泛型類或泛型方法都會產生一份object code
C# 2.0加入泛型,.NET是在CLI(common language implementation)加入泛型支援,性能較好,且可以在runtime時期取得泛型類或泛型方法的實際型別資訊

參考資料:
Java魔法堂:解讀基於Type Erasure的泛型
https://www.cnblogs.com/fsjohnhuang/p/4288614.html

聊聊Java泛型類型擦除及Flink類型暗示(type hint)機制
https://www.jianshu.com/p/cfb8c1386f69

Type Erasure
https://docs.oracle.com/javase/tutorial/java/generics/erasure.html

https://stackoverflow.com/questions/355060/c-sharp-vs-java-generics

https://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-sharp-and-java-and-templates-i

C# vs Java : Generics
http://toddgerspacher.blogspot.com/2017/07/c-vs-java-generics.html

Generics in Java
https://en.wikipedia.org/wiki/Generics_in_Java#Problems_with_type_erasure

Generics in the Run Time (C# Programming Guide)
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generics-in-the-run-time

.NET Column: Introducing Generics in the CLR
https://docs.microsoft.com/en-us/archive/msdn-magazine/2003/september/net-column-introducing-generics-in-the-clr
Finally, the research group at Microsoft has modified a version of the shared source common language implementation (CLI), code-named "Rotor," to include generics support.

https://dotnetfiddle.net/MEK7FM