Created
November 28, 2014 03:03
-
-
Save EfrainReyes/1b9f54c1d8089a45beb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormsAuthenticationService : IFormsAuthenticationService | |
{ | |
private readonly HttpContextBase _context; | |
public FormsAuthenticationService(HttpContextBase context) { | |
_context = context; | |
} | |
public void SignIn(string userName, bool createPersistentCookie, IEnumerable<string> roles = null) { | |
string roleList = string.Empty; | |
if (roles != null) | |
roleList = string.Join(",", roles); | |
var authTicket = new FormsAuthenticationTicket( | |
1, | |
userName, | |
DateTime.Now, | |
DateTime.Now.AddDays(30), | |
createPersistentCookie, | |
roleList, | |
"/"); | |
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); | |
if (authTicket.IsPersistent) { | |
cookie.Expires = authTicket.Expiration; | |
} | |
_context.Response.Cookies.Add(cookie); | |
} | |
public void SignOut() { | |
FormsAuthentication.SignOut(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment