Thursday, January 23, 2014

How to log the user out using FormsAuthentication.SignOut()

FormsAuthentication.SignOut();
Session.Abandon();
 
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
cookie1.Path = FormsAuthentication.FormsCookiePath;
cookie1.HttpOnly = true;
 
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId""");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
 
FormsAuthentication.RedirectToLoginPage();

How to Disable RequiredFieldValidator with javascript

<script>
    ValidatorEnable(document.getElementById('RequiredFieldValidator1'), false);
</script>