Serenity.WebSecurityHelper.SetAuthenticationTicket C# (CSharp) Method

SetAuthenticationTicket() public static method

Sets authentication cookie.
public static SetAuthenticationTicket ( string username, bool persist ) : void
username string /// Validated Username (required).
persist bool /// is persistent authentication tikcet? (remember me, we don't use this for reasons considering with security)
return void
        public static void SetAuthenticationTicket(string username, bool persist)
        {
            if (username == null)
                throw new ArgumentNullException(username);

#if ASPNETCORE
            var principal = new GenericPrincipal(new GenericIdentity(username), EmptyStringArray);
            var httpContext = Dependency.Resolve<IHttpContextAccessor>().HttpContext;
            httpContext.Authentication.SignInAsync("CookieAuthenticationScheme", principal).Wait();
#else
            HttpCookie authCookie = FormsAuthentication.GetAuthCookie(username, persist);
            HttpContext.Current.Response.Cookies.Remove(authCookie.Name);
            HttpContext.Current.Response.Cookies.Add(authCookie);
#endif
        }