Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public static void SignOut()
  2. {
  3. Initialize();
  4. HttpContext current = HttpContext.Current;
  5. bool flag = current.CookielessHelper.DoesCookieValueExistInOriginal('F');
  6. current.CookielessHelper.SetCookieValue('F', null);
  7. if (!CookielessHelperClass.UseCookieless(current, false, CookieMode) || current.Request.Browser.Cookies)
  8. {
  9. string str = string.Empty;
  10. if (current.Request.Browser["supportsEmptyStringInCookieValue"] == "false")
  11. {
  12. str = "NoCookie";
  13. }
  14. HttpCookie cookie = new HttpCookie(FormsCookieName, str);
  15. cookie.HttpOnly = true;
  16. cookie.Path = _FormsCookiePath;
  17. cookie.Expires = new DateTime(0x7cf, 10, 12);
  18. cookie.Secure = _RequireSSL;
  19. if (_CookieDomain != null)
  20. {
  21. cookie.Domain = _CookieDomain;
  22. }
  23. current.Response.Cookies.RemoveCookie(FormsCookieName);
  24. current.Response.Cookies.Add(cookie);
  25. }
  26. if (flag)
  27. {
  28. current.Response.Redirect(GetLoginPage(null), false);
  29. }
  30. }
  31.  
  32. current.Request.Browser["supportsEmptyStringInCookieValue"]
  33.  
  34. HttpContext.Current.Request.Browser.SupportsEmptyStringInCookieValue
  35.  
  36. CookielessHelperClass.UseCookieless(current, false, CookieMode)
  37.  
  38. HttpContext.Current.Request.Browser = new HttpBrowserCapabilities() { Capabilities = new Dictionary<string, string> { { "supportsEmptyStringInCookieValue", "false" } } };
  39.  
  40. public interface IFormsAuthenticationWrap
  41. {
  42. void SignOut();
  43. }
  44.  
  45. public class FormsAuthenticationWrap : IFormsAuthenticationWrap
  46. {
  47. public void SignOut()
  48. {
  49. FormsAuthentication.SignOut();
  50. }
  51. }
  52.  
  53. public class LogOutClass
  54. {
  55. private readonly IFormsAuthenticationWrap _formsAuthentication;
  56.  
  57. public LogOutClass() : this (new FormsAuthenticationWrap())
  58. {
  59. }
  60.  
  61. public LogOutClass(IFormsAuthenticationWrap formsAuthentication)
  62. {
  63. _formsAuthentication = formsAuthentication;
  64. }
  65.  
  66. public void LogOutMethod()
  67. {
  68. // Code before SignOut
  69.  
  70. _formsAuthentication.SignOut();
  71.  
  72. // Code after SignOut
  73. }
  74. }
  75.  
  76. public class FormsAuthenticationStub : IFormsAuthenticationWrap
  77. {
  78. public void SignOut()
  79. {
  80. }
  81. }
  82.  
  83. [TestMethod]
  84. public void TestLogOutMethod()
  85. {
  86. var logOutClass = new LogOutClass(new FormsAuthenticationStub());
  87. logOutClass.LogOutMethod();
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement