發表文章

目前顯示的是 8月, 2018的文章

[VS2017] 自動換行

[VS2017] 自動換行 開啟 Visual Stdio , 選取上面的工具,選項,文字編輯器,所有語言,一般選項中,有個 Word Wrap 選項,將他打勾,後續的文件,程式碼,只要超過編輯器預設的寬度,即會自動換行。

[Middleware] Using Middleware in Asp.Net Core

[Middleware] Using Middleware in Asp.Net Core 因為在 Asp.Net Core 中,它本身是一個管線的概念,Middleware 本身就是坐落在管線之中,所以我們可以透過 Middleware , 一直在管線中,安插我們想要執行的一些程式邏輯。 Middleware Middleware 基本上需要注入 RequestDelegate,也需要實作 Invoke 方法。有一點需要注意的是,在 Invoke 中,一定要呼叫 RequestDelegate 方法, 否則管線運行時,運行到此 middleware 就會停止於目前的管線中。 public class MyMiddleware { public MyMiddleware(RequestDelegate next) { _next = next; } public RequestDelegate _next { get; } public async Task Invoke(HttpContext context) { Console.WriteLine("Hello, I am in Middleware!"); await _next(context); } } Configure // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // 將 Middleware 排入 管線中 app.UseMiddleware<MyMiddleware>(); app.UseMvc(); } Result MiddlewareExam...

[Sniffer] Sniffer Wireless Packet on Mac

[Sniffer] To sniffer wireless packets on Mac 由於對 Mac 不熟,但是想抓一些無線的封包,所以 google 一下,順便筆記。 新增 airport 連結 $ sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport airport $ airport Usage: airport <interface> <verb> <options> <interface> If an interface is not specified, airport will use the first AirPort int erface on the system. <verb is one of the following: prefs If specified with no key value pairs, displays a subset of AirPo rt preferences for the specified interface. Preferences may be configured using key=...

[Swagger&ExtensionService] Adding Swagger and Extensions to ASP.NET Core Web API using XML Documentation

Adding Swagger and Extensions to ASP.NET Core Web API using XML Documentation 之前一直在想,很多服務與設定檔都集中在 Startup.cs 裡面,可是東西服務很多,整個 Configure 與 ConfigureServices 就會越來越肥,但是很不喜歡這樣,很想把類似相關聯的東西集中在一起。Google 看看,做筆記一些筆記,順便研究該怎麼把那些東西從 Startup 中抽離出來。 Startup Startup 類似是以前 ASP.NET 的 Global.asax。它掌管整個系統的設定檔,與要運行那些服務到管線中。它主要分成兩個部分,一個是 Configure 與 ConfigureServices。 ConfigureServices ConfigureServices 主要是掌管註冊服務到的ASP.NET Core的服務容器。 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } Configure Configure 主要是將要運行的程式或是路由一些設定到後續程式運行的管線中。 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { ...