Showing posts with label Authentication. Show all posts
Showing posts with label Authentication. Show all posts

Wednesday, August 1, 2012

Logout User In Asp.net Membership

While developing usermanagement based web application using Membership provider, many times we come across some trivial issues or queries as follows
  • formsauthentication.signout not working
  • Using formsauthentication.signout
  • logout user programmatically
  • Check user date subscription and log out if user is not valid.
  • programmatically logout in asp net
  • Logout user in asp.net Membership
Solution for all above queries is as follows
FormsAuthentication.SignOut();
  Session.Abandon();

 // clear authentication cookie
 HttpCookie frmcookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
 frmcookie.Expires = DateTime.Now.AddYears(-1);
 Response.Cookies.Add(frmcookie);

 // clear session cookie if we use any
 HttpCookie sessioncookie = new HttpCookie("ASP.NET_SessionId", "");
 sessioncookie.Expires = DateTime.Now.AddYears(-1);
 Response.Cookies.Add(sessioncookie);

 FormsAuthentication.RedirectToLoginPage("v=SubscriptionExpired");
Above code signout the user, remove all the Cookies set. Forms Authentication.RedirectToLoginPage uses settings in web.config file. We can pass Querystring to the function so that we can show proper Messages.
Submit this story to DotNetKicks

Read more...

Tuesday, July 31, 2012

Form Authentication Is Not Working

Form Authentication Is Not Working in IE 8. I am working on one web based project where I started with user management and struggled to make Form Authentication work... :( without testing it on other browsers. I had following settings in web.config...

      
    

After struggling for the day on "Form Authentication Is Not Working" and to Make it work... I tested it in Firefox and Google Crome and it did work very well :(, without any error. What I realized is, there is some Issue with IE 8 and Cookies we are using for Form authentication, so I made following change in Web.Config Setting.

      
    

Which in turn changed URL for IE 8 by adding some encoded information as a part of URL (going cookie-less), and in other browsers it allowed cookies and URL was without any Encoding added i.e. it was using Cookies. I hope this piece of Information will be Useful.
Submit this story to DotNetKicks

Read more...