Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public void Configure(IApplicationBuilder app)
  2. {
  3. app.UseStaticFiles();
  4. app.UseCookiePolicy();
  5. app.UseAuthentication();
  6.  
  7. app.Use(async (ctxt, next) =>
  8. {
  9. if(ctxt.User == null)
  10. {
  11. // Not logged in, so nothing to do.
  12. await next();
  13. }
  14. else
  15. {
  16. // Set a scoped value in the NLog context, then call the next
  17. // middleware.
  18. var userName = ctxt.User.Identity.Name;
  19. using (MappedDiagnosticsLogicalContext.SetScoped("userName", userName))
  20. {
  21. await next();
  22. }
  23. }
  24. });
  25.  
  26. app.UseMvc(routes =>
  27. {
  28. routes.MapRoute(
  29. name: "default",
  30. template: "{controller=Home}/{action=Index}/{id?}");
  31. });
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement