2026年7月29日 星期三

內部 IIS 設定 SSL

Chrome 及大部份的瀏覽器對於沒有安裝HTTPS 的網站,都會出現警告甚至想連進去都要半強迫連線。對於一些小網站或是沒有資安考量的資料分享網站的確是件麻煩事,重點是得花錢買SSL憑証,這種類似過路費的方式我覺得又是商人的手法。

平常公司內部,只開放內網連線網站也要安裝SSL倒是有點畫蛇添足,中小企業內部使用的網站通常會用IP直連,例: http://192.168.0.1/erp,或是直接用主機名稱連線 http://server/erp,這時連線內部網站就出現沒有 HTTPS的警告,只能找些簡單的方式,不花錢的方式設定SSL憑證。此次就試著設定IIS+HTTPS的步驟作個記錄。

 1 設定 DNS 新增網址

設定 DNS 新增網址


2 設定 IIS HTTPS 網站




3 執行 win-acme 安裝 Let’s Encrypt 憑證

憑證有效日期是三個月,可以手動更新或是建立 schedule task 自動更新。

4 設定 router NAT RTF8207W-E



參考資料:  https://ithelp.ithome.com.tw/articles/10260641 

2026年4月24日 星期五

Vue 引用錯誤: Missing ref owner context. ref cannot be used on hoisted vnodes.

- 錯誤訊息
[Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function. 

  - 引用前端插件 
Vue: v3 
chart.js: v4+ 
vue-chartjs: v5+ 

  - 說明 
此測試程式是 CDN 方式,以輕前端方式開發,所以手動引用 plug-in。初期猜測是程式中的語法造成此錯誤,但多方 try-error 加上網路上資料後仍不得解。 有中國網友 PO 文提到這個問題,但說明不太清楚還是卡在這個錯誤無法產生圖表。最後心血來潮將 vue-chartjs 引用 ESM 改為一般的 JS 檔案,順利解決。 



    


- 參考資料 
解决vue-chartjs在ESM模块导入时出现的引用错误问题 https://blog.gitcode.com/8eb95d906b3286a46aee671826e0d9f8.html

2020年5月13日 星期三

WeMos D1 測試 OUTPUT 錯誤

最近測試一塊WeMos D1 WiFi Arduino UNO 開發板ESP8266,測試輸出時總是失敗,一下懷疑板子問題,一下懷疑電源問題。總算找到這個微不足道的解法:配合接腳號由 4 改為 D4。

2018年11月18日 星期日

VS2017 打包安裝檔問題–管理者權限

Win10 的安全性比較嚴謹,自行開發的程式安裝後執行會出現漏斗轉個幾下就停止了,這個況狀還不是出現程式無回應就是 Win10 直接就結束程式。最簡單的解決方式是在圖示上按右鍵選擇:以系統管理員身份執行
image
不過要請使用者每回都要選擇”以系統管理員身份執行”,的確是有些麻煩。經過網路找解法,試過 app.manifest 中設定 requireAdministrator,但程式仍直接被 Win10 關閉。最後找到直接寫 code 提示使用者需要系統管理員權限的題示畫面,但使用者只要按下 “是” 就可以執行。
image

以下 sample code 來源: https://dotblogs.com.tw/alexwang/2016/09/21/234628
 [STAThread]
        static void Main()
        {
            var wi = WindowsIdentity.GetCurrent();
            var wp = new WindowsPrincipal(wi);

            if (!wp.IsInRole(WindowsBuiltInRole.Administrator))
            {
                var processInfo = new ProcessStartInfo();
                // The following properties run the new process as administrator
                processInfo.UseShellExecute = true;
                processInfo.FileName = Application.ExecutablePath;
                processInfo.Verb = "runas";

                // Start the new process
                try
                {
                    Process.Start(processInfo);
                }
                catch (Exception ex)
                {
                    // The user did not allow the application to run as administrator
                    MessageBox.Show("Sorry, this application must be run as Administrator.\n" + ex.Message);
                }

            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form2());
            }
        }

2018年8月14日 星期二

C# 小撇步

C# 6.0 dictionary 初始化的新寫法

var dict = new Dictionary<string, int>
{
    ["one"] = 1,
    ["two"] = 2,
    ["three"] = 3
};

2018年7月31日 星期二

.NET MapHttpRoute 與 MapPageRoute

需求: URL 輸入 http://xxxx/yyy 轉成 http://xxxx/yyy.html

最近趕流行,用 vue 寫了一個 SAP(Single application page),html網頁在 MVC 的架構下可成功執行,但我就是想讓使用者操作上更方便,只要輸入網址 route 就直接跳轉到此 html 頁面。如果照原本 MapHttpRoute的方式會造成 .NET 出現找不到 Controller 的問題。最後發現不用 MapHttpRoute 去解此問題,使用MapPageRoute才是正解。

            // Web API routes
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );


以下增加於 Global.asax.cs  

    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            GlobalConfiguration.Configure(WebApiConfig.Register);
            // 新增加以下 route 
            RegisterRoutes(RouteTable.Routes);
        }
        void RegisterRoutes(RouteCollection routes)
        {
            routes.MapPageRoute("",
                        "yyy", "~/yyy.html");
        }
    }

Web.Config 加上對應的 extension
<compilation debug="true" targetFramework="4.5.2">
<buildProviders >
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
<add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders >
</compilation>

2018年5月10日 星期四

泰國佛曆 System.Globalization.CultureInfo

手上有個泰國的生產系統小案子,
雖說是個小案子但也算是跨國專案,
我遇到除了語言不同之外的電腦系統文化差異,
平常我們使用電腦的日期格式一般主要為2018/5/10,
美國系統的國家則是 5/10/2018,也就是 MM/dd/yyyy。
但泰國的使用曆別是一個本人未曾耳聞的佛曆,
就是釋迦牟尼佛滅度(涅槃)當年度為計算基準,
西元2018年就是泰曆/佛曆2561年,年度不同就算了還有四年一次閏年。
真要弄起來那就頭疼了。

不過在網路上找到一個小解法,
執行的程式強制指定CultureInfo,
為了這個設定我可是弄到凌晨三時多,真是工程師的悲哀。
以下為其語法,分享給作泰國專案的網友們。

string theCultureString = “zh-TW”; // 台灣南波萬
System.Globalization.CultureInfo ci = new CultureInfo(theCultureString); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci;


加碼再作個記錄,此專案使用到一個強大元件:GrapeCity Spread
雖然事前設定CurrentThread的CultureInfo,
但日期資料在輸入時仍有被我佛慈悲的佛曆帶著走,
還是得強迫在 cell 設定CultureInfo處理日期。

// 強制使用台灣 Culture, 避免泰國佛曆造成衝突 
string theCultureString = "zh-TW" System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(theCultureString); datecell.SetCurrentCulture(ci);

image
佛曆設定方式

資料來源:
https://stackoverflow.com/questions/468791/is-there-a-way-of-setting-culture-for-a-whole-application-all-current-threads-a