Guest User

Untitled

a guest
Dec 11th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. services.AddDistributedMemoryCache();
  4. services.AddSession(options =>
  5. {
  6. options.IdleTimeout = TimeSpan.FromDays(10);
  7. options.CookieHttpOnly = true;
  8. });
  9. services.AddMvc();
  10. }
  11.  
  12. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  13. {
  14. app.UseSession();
  15. app.UseStaticFiles();
  16. app.UseDeveloperExceptionPage();
  17. app.UseMvc(routes =>
  18. {
  19. routes.MapRoute(
  20. name: "default",
  21. template: "{controller=Home}/{action=Index}/{id?}");
  22. });
  23. }
  24.  
  25. @inject ISession Session
  26.  
  27. @inject Microsoft​.AspNetCore​.Http.IHttpContextAccessor HttpContextAccessor
  28.  
  29. @if(HttpContextAccessor.HttpContext.Session ...)
  30.  
  31. services.AddHttpContextAccessor();
  32.  
  33. @inject Microsoft​.AspNetCore​.Http.IHttpContextAccessor HttpContextAccessor
  34. @{
  35. var session = HttpContextAccessor.HttpContext.Session;
  36. }
Add Comment
Please, Sign In to add comment