The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SessionExtensions.cs 640B

1234567891011121314151617181920212223
  1. using Microsoft.AspNetCore.Http;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Teknik.Utilities
  7. {
  8. public static class SessionExtensions
  9. {
  10. public static void Set<T>(this ISession session, string key, T value)
  11. {
  12. session.SetString(key, JsonConvert.SerializeObject(value));
  13. }
  14. public static T Get<T>(this ISession session, string key)
  15. {
  16. var value = session.GetString(key);
  17. return value == null ? default(T) :
  18. JsonConvert.DeserializeObject<T>(value);
  19. }
  20. }
  21. }