發表文章

目前顯示的是有「Programming」標籤的文章

Application Insight 資料取樣設定

圖片
最近在查系統問題,為了追查使用者傳送的參數與系統使用狀況時,查看 Application Insight 紀錄時,卻發現紀錄明顯比實際傳送過的訊息少! 原來是因為 Application Insight 在所有最新版本的 ASP.NET 和 ASP.NET Core SDK 中預設啟用調適型取樣 (Adaptive Sampling),也就是依據資料數量進行取樣調整,以減少流量與資料成本。 確認目前取樣比例: 查看方式為: Step 1. 登入 Azure Portal Step 2. 開啟 Web App 對應的 Application Insight 查詢視窗 Step 3. 輸入以下指令: union requests,dependencies,pageViews,browserTimings,exceptions,traces | where timestamp > ago(1d) | summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType Application Insight 取樣模式: 有以下三種取樣模式: 調適型取樣 ( Adaptive sampling ): 系統自動調整 ASP.NET/ASP.NET Core 應用程式中從 SDK 傳送的遙測量;為預設模式 固定速率取樣 ( Fixed-rate sampling ): 比例由開發者自行設定。 用戶端和伺服器會同步處理它們的取樣 內嵌取樣 ( Ingestion sampling ): 適用於 Azure 入口網站,根據自訂的取樣比例,捨棄來自應用程式的一些遙測資料。不會減少從應用程式傳送的遙測流量,但可協助讓流量不要超過每月配額。 停用取樣 為了記錄所有應用程式使用狀況,需要停用取樣,根據不同程式版本,關閉取樣的設定方式也不同: 非 ASP.Net Core (例如 .Net Framework): 尋找在專案中的設定檔 - ApplicationInsights.config 中,將 AdaptiveSamplingTelemetryProcessor 節點移除或設成註解。 ( 參考來源 ) ...

ASP.NET Core API 指定回傳格式為 json

圖片
【狀況】 使用 ASP.NET Core 站台建置 API 時,回傳 Guid 字串時,前端(Angular)發生 Exception 【原因】 回傳內容格式,格式被設定為 text 【修正】 在 Controller 宣告處加上  [Produces("application/json")] 回傳格式就會自動設定為 json 以上,收工!

ASP.NET Core中文編碼

最近在處理字串加密過程中,需要指定編碼做內容轉換, 意外踩到了 .NET Core 編碼的坑。 起因是這段程式碼: private static string PlainTextToHex(string str) { byte[] strBytes = Encoding.GetEncoding("BIG5").GetBytes(str); string strHEX = BitConverter.ToString(strBytes); strHEX = strHEX.Replace("-", ""); return strHEX; } 在取得 Encoding 時會出現以下錯誤訊息: 'BIG5' is not a supported encoding name. 原來是 .NET Core 僅保留最常用的編碼, (詳細支援清單請見下方 MSDN 連結) 其他編碼器需另外安裝 使用步驟: 1. 開啟 Package Manager Console,輸入以下指令 Install-Package System.Text.Encoding.CodePages 2. 註冊編碼提供者: 需註冊後才能使用額外編碼,可將以下程式碼放在程式入口 (例如:Startup 中) Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 做完就可以快樂使用囉~ 參考來源: 1.  [.NET Core] Encoding.GetEncoding(950) 取得繁體中文失效 !? 2. MSDN: Encoding Class

Node.js 爬蟲練習 - 牌告匯率

圖片
在網路上亂逛的時候,發現可以利用 Node.js 來爬蟲, 那麼,就讓我們拿臺銀的匯率網頁來做練習吧!

Form Builder架構篇

圖片
最近在做類似線上 Form Builder 的專案,在此整理相關資料。 架構 Server Side:  NodeJS Client Side ( MVC / MVVM):  EJS : 優點 - 語法簡單易學 缺點 - 無法雙向binding   CanJS : 優點 - 可使用EJS語法設計樣板,語法簡單易學、引入 Observe 架構支援雙向Binding 缺點 - 因最終產生 Angular2 專案,需同時維護 EJS/Angualr2 兩架構之樣板 Angular2 : 優點 - 支援雙向Binding 缺點 - 功能豐富且複雜,Render 功能使用此架構略嫌複雜 architecture diagram ( 參考來源 ) [閱讀清單] CanJS API Developing a MEAN app with Angular 2.0 MEAN App with Angular 2 and the Angular CLI Drag & Drop with pure JavaScript Angular vs React 如何選擇?

如何在Silverlight中建立預設頁面

Silverlight 建立UI的方式,是透過 Application.RootVisual 屬性指定要載入的XAML 檔案。 所以,開啟一個基本的 Silverlgiht 專案來看,在  App.xaml.cs  中Application_Startup,指定了這程式會載入哪個 XAML 頁面當成主要的程式介面: private void Application_Startup( object sender, StartupEventArgs e) {       this .RootVisual = new MainPage (); } 在 App(繼承Application) 中的 this.RootVisual  就是  Application.Current.RootVisual 。 而在 MainPage (繼承UserControl) 類別中,就有包含XAML定義,因此,指定此類別後,RootVisual實際會載入類別中的的 content 對象。 如果想改變載入的畫面,就可以修改指定給 RootVisual 的類別名稱。 例如:       根據使用者選擇,開啟不同頁面: private void  Application_Startup( object  sender,  StartupEventArgs  e) { switch  (selection) { case  1: this .RootVisual =  new   PageStyle1 ();            break ;        default :            this .RootVisual =...