code_junkie

How to provide a Session/Host object for use in both a windows and web application?

Nov 11th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. ((UserSession)HttpContext.Current.Session["UserSession"]).User.Info
  2.  
  3. IHost.User.Info
  4.  
  5. ((UserSession) DualContext.Current["UserSession"]).User.Info
  6.  
  7. public class DualContext
  8. {
  9. private Dictionary<string, object> winFormsSession = new Dictionary<string, object>();
  10. private static readonly DualContext instance = new DualContext();
  11.  
  12. public static DualContext Current
  13. {
  14. get { return instance; }
  15. }
  16.  
  17. public object this[string key]
  18. {
  19. get
  20. {
  21. if (HttpContext.Current != null)
  22. return HttpContext.Current.Session[key];
  23. else
  24. return winFormsSession[key];
  25. }
  26. set
  27. {
  28. if (HttpContext.Current != null)
  29. HttpContext.Current.Session[key] = value;
  30. else
  31. winFormsSession[key] = value;
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment