Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Middleware in ASP.NET Core 2.x

Middleware in ASP.NET Core 2.x

At the core of ASP.NET Core is Microsoft’s implementation of the OWIN standard, giving developers full control over the ASP.NET pipeline. In this session I will explain what OWIN is and how it can empower you to quickly and easily reconfigure an entire web application. Now in full control, you can do everything from injecting custom code (middleware) into any stage of the pipeline to running lightweight applications and microservices without MVC.

Avatar for ondrejbalas

ondrejbalas

July 13, 2018
Tweet

More Decks by ondrejbalas

Other Decks in Technology

Transcript

  1. ONDREJ BALAS Microsoft MVP in Developer Technologies Blog at ondrejbalas.com

    Consultant since 2001 Founded startup in 2017 Game development for fun WWW.ONDREJBALAS.COM [email protected] @ONDREJBALAS
  2. Middleware is for cross-cutting concerns Logging Access Control (Authentication &

    Authorization) Routing Serving Special Content Any other time you want to do some THING between receiving a request and returning a response, even if that THING is preventing something else from happening.
  3. MVC

  4. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) app.UseDeveloperExceptionPage();

    else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); Startup.cs
  5. MVC CookiePolicy CookiePolicy HttpsRedir StaticFiles Developer ExceptionPage public void Configure(IApplicationBuilder

    app, IHostingEnvironment env) if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
  6. MVC CookiePolicy CookiePolicy HttpsRedir StaticFiles Hsts ExHandler public void Configure(IApplicationBuilder

    app, IHostingEnvironment env) if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
  7. // Do something before await _next(context); // Do something after

    Middleware // Do something before await _next(context); // Do something after
  8. // Do something before await _next(context); // Do something after

    Middleware // Do something before await _next(context); // Do something after // Do something before await _next(context); // Do something after
  9. // Do something before await _next(context); // Do something after

    Middleware // Do something before await _next(context); // Do something after // Do something before await _next(context); // Do something after String Appender Static File MVC
  10. // Do something before await _next(context); // Do something after

    Middleware // Do something before await _next(context); // Do something after // Do something before await _next(context); // Do something after String Appender Static File MVC