asp.net mvc - CurrentPrincipal.Identity.IsAuthenticated is true even after signout when FormsAuth cookie domain set manually -
refering sharing cookie in subdomains implemented jro's answer , worked sign in. (sharing cookie in different sub domains)
however change effected signout process. please refer signout , signin code shared below.
the issue in signout process formsauthentication.signout , redirect sign in controller, "system.threading.thread.currentprincipal.identity.isauthenticated" set true though formsauthentication.signout called in sign out process.
code sets forms authentication cookie
public static httpcookie getauthenticationcookie(cookiedata cookiedata) { string userdata = preparecookiecontentfromcookiedata(cookiedata); //get string user data authenticationsection section = webconfigurationmanager.getwebapplicationsection("system.web/authentication") authenticationsection; timespan ts = section.forms.timeout; int timeout = (ts.minutes != 0) ? timeout = ts.minutes : 1; bool ispersistent = convert.toboolean(httpcontext.current.request.form["ispersistent"] ?? "false"); if (ispersistent) timeout = 30 * 24 * 60; //ticket object formed based on above details set. evry page afer login use ticket base user data formsauthenticationticket ticket = new formsauthenticationticket(1, cookiedata.username, datetime.now, datetime.now.addminutes(timeout), ispersistent, userdata, formsauthentication.formscookiepath); // encrypt ticket string encryptedcookiestring = formsauthentication.encrypt(ticket); // setting ticket cookie. var cookie = new httpcookie(formsauthentication.formscookiename, encryptedcookiestring); cookie.httponly = true; cookie.domain = "parent.com"; if (ispersistent) cookie.expires = datetime.now.addyears(1); return cookie; } sign out
public actionresult signout() { if (httpcontext != null && httpcontext.session != null) { httpcontext.session.abandon(); } formsauthentication.signout(); } return redirecttoaction("signin", "user"); } signin
public actionresult signin(string companycode) { //check if logged in if (system.threading.thread.currentprincipal.identity.isauthenticated) { //return specific page } } appreciate on this.
you have set currentprincipal , user null in signout method
public class logoffcontroller : controller { public actionresult index() { formsauthentication.signout(); httpcontext.user = null; thread.currentprincipal = null; return view(); } } hope help.
Comments
Post a Comment