martes, 26 de junio de 2018
ASP.Net Login Control - How to write code to manually Login
In my case I had to apply an auto login feature to one of our web applications, but it is using the ASP.Net Login Control, which it was difficult to write code to login the system manually without using the Login Control...
In order to follow up with this tutorial you need to read the previous one, please see here
https://edgarvzla.blogspot.com/2018/06/aspnet-login-control-how-to-get-users.html
Once you have completed with the steps into my tutorial above, please continue with the code below to validate and login the user:
bIsAuthenticated = Membership.ValidateUser(UserId, sPassword);
HttpContext.Current.Session["IsAuthenticated"] = bIsAuthenticated;
if ( bIsAuthenticated)
{
HttpContext.Current.Session["UserName"] = UserId;
IIdentity identity = new GenericIdentity(UserId);
IPrincipal principal = new GenericPrincipal(identity, null);
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;
FormsAuthentication.SetAuthCookie(UserId, true);
}
Suscribirse a:
Comentarios de la entrada (Atom)
No hay comentarios.:
Publicar un comentario