13.07.2015 Views

Creando objetos GenericPrincipal con autenticación ... - Willy .Net

Creando objetos GenericPrincipal con autenticación ... - Willy .Net

Creando objetos GenericPrincipal con autenticación ... - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FormsAuthenticationTicket(1,// versiontxtUserName.Text, // user nameDateTime.Now, // creationDateTime.Now.AddMinutes(60),// Expirationfalse,// Persistentroles ); // User data8. Agregue código para crear una representación de cadena cifrada del vale yalmacenarla como datos en un objeto HttpCookie.// Now encrypt the ticket.string encryptedTicket = FormsAuthentication.Encrypt(authTicket);// Create a cookie and add the encrypted ticket to the// cookie as data.HttpCookie authCookie =new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket);9. Agregue la cookie a la colección de cookies que se devuelven al explorador delusuario.// Add the cookie to the outgoing cookies collection.Response.Cookies.Add(authCookie);10. Redirija al usuario a la página solicitada originalmente}// Redirect the user to the originally requested pageResponse.Redirect( FormsAuthentication.GetRedirectUrl(txtUserName.Text,false ));4. Construir <strong>objetos</strong> <strong>GenericPrincipal</strong> y FormsIdentityEn este procedimiento se implementa un <strong>con</strong>trolador de eventos de autenticación deaplicación y se <strong>con</strong>struyen <strong>objetos</strong> <strong>GenericPrincipal</strong> y FormsIdentity basados en lainformación <strong>con</strong>tenida en el vale de autenticación. Para <strong>con</strong>struir <strong>objetos</strong> <strong>GenericPrincipal</strong> y FormsIdentity1. En el Explorador de soluciones, abra global.asax.2. Cambie a la vista de código y agregue las siguientes instrucciones using alprincipio del archivo:using System.Web.Security;using System.Security.Principal;3. Busque el <strong>con</strong>trolador de eventos Application_AuthenticateRequest y agregueel siguiente código para obtener la cookie de autenticación mediante Formulariosde la colección de cookies que se pasó <strong>con</strong> la solicitud.5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!