2016年12月18日 星期日

使用 asp.net core實作一個類 google blog的網站



 

之前有分享過 試作 CKEditor 圖片選擇器 ( image upload ),利用 ckeditor和客制 image picker
來達成圖片選取,但是圖片的處理、儲存還沒實作完成,最近剛好寫完預算系統,所以利用空檔來繼續完成這個部份,完成工作內容如下:

2016年12月7日 星期三

ASP.NET Core Render View to String in Controller

參考文章:
ASP.NET Core Render View to String
Render a Razor View containing a URL to a string in ASP.NET Core

這個目的是直接在 controller直接產生 partial view的字串再回傳至 view ajax result,然後直接把某個 element換掉或作內文休改,這種方式當然也有其它的方式達成,但直接在 contorller內產生 view string也是可以試試,因為在 Asp.net MVC 5也有類似的作法或是直接使用 westwind的 library。但在 Asp.net Core就不能直接拿來用。所以參考上面的分享文章就可以達到目的了。

AntiXss Library for Asp.Net Core

之前在 Asp.Net MVC 5時會使用 微軟的 AntiXSS Library
而在 Core專案的 Library,我有找到一個叫 SmallCode.AspNetCore.AntiXSS
這個 library不只在 controller內使用 HtmlFilter.Instance.SanitizeHtml 方法還在 view有提供 tag helper @Html.Sanitized可以使用。 如果需要的話可以使用 nuget下載使用。

2016年11月22日 星期二

Asp.Net Core MVC Paging使用了 cloudscribe.Web.Pagination

之前開發 MVC 5專案參考了 ASP.NET MVC 資料分頁 MVCPaging 2.0 應用分享文章,使用了 MVCPaging開發分頁需要的程式,但到 Core之後 MVCPaing官網建議要使用   cloudscribe.Web.Pagination library。

使用 Nuget安裝後要先設定
Startup.cs 要加上 services.AddCloudscribePagination();
_ViewImports.cshtml 要加上@addTagHelper "*, cloudscribe.Web.Pagination"

程式是最大的改變應該是在 View的部份,原本在顯示 page info的部份改寫如下:

<cs-pager asp-action="Index" asp-controller="Paging" 
     cs-pagenumber-param="page" 
     cs-paging-pagenumber="@Model.PageNumber" 
     cs-paging-pagesize="@Model.PageSize" 
     cs-paging-totalitems="@Model.TotalItemCount">
</cs-pager>

測試後的結果應該是沒問題,後續還是要測試每個 tag attribute




2016年11月21日 星期一

Connect(); // 2016


Connect(); // 2016

Xamarin.Forms有 Previewer了

分享文章:Live XAML Previewing with the Xamarin.Forms Previewer官方 Xamarin.Forms Previewer

在今天 10月參加 Microsoft Tech Summit 台北場次,第二天有幾場是關於 Xamarin,我就參加其中的一場 (An Overview of the Microsoft Application Platform for Developers),講師有介紹目前開發 Xamarin專案可以有兩種選擇方式一種就是 Xamarin.Forms,另一種是  Platform-specific,Xamarin.Forms Guides的 Is Xamarin.Forms right for your project?小節上有建議。

那場演講上有提供 platform-specific的專案是可以有 GUI工具可以拉元件進行設計,但 Xamarin.Form的方式就沒有,所以會後就問講師 David Carmona Xamarin Forms是否未來也會有 GUI的設計方式,他的回答說應該會有吧,不過不知道那時會出現,想不到今天就看到這篇文章,我只能說除了 Docker之外,愈來愈愛 C#了。

開啟 previewer: View(檢視) - Other windows(其它視窗) - Xamarin.Forms Previewer

2016年11月10日 星期四

再見了 Web.config,Asp.Net Core使用了 appsettings.json

官網:Asp.Net Core Configuration

其它連結:
The New Configuration Model in ASP.NET Core
No ConfigurationManager in ASP.NET Core

長久以來,不管是 Asp.Net MVC或是 Form的開發,一定要使用到 Web.config,而在程式碼內就會使用到 ConfigurationManager來取得資料庫連線字串 (ConnectionStrings)或是自定變數,但是在 Core已經不採用這樣的方式了,所以要參考上面的文章,要自訂類別,在 startup.cs內來儲存 appsettings.json的變數,而在 controller才可以利用系統 DI方式取得想要的設定值,雖然一開始可能不太適應,但萬事起頭難,用久就會習慣了。