Esta sencilla acción era lo que necesitaba Alexa (desde los newsgroup de ASP.NET)…quien me llevo a escribir este presente post.
Cual es la necesidad (.. de Alexa)??
No necesitaba la “funcionalidad” de redirección que realiza por defecto el Proveedor de Membresia cuando utilizamos la autenticación de formularios, cuando envía a la pagina de Login el parámetro por QueryString de ReturnUrl
Mas info: Flujo de control de autenticación de formularios
Porque por defecto cuando asignamos la seguridad y solicitamos la pagina:
http://www.miempresa.com/principal.aspx
se redirección para la petición de credenciales (user/pass) a la pagina:
http://www.miempresa.com/login.aspx?ReturnUrl=principal.aspx
La solución que recomendé, por no conocer otra posibilidad 😉 (escuchamos en los comentarios alguna otra alternativa)
Esto es similar a:
Solución
Al momento de logearse el usuario redireccionar al lugar deseado, esto es el evento LoggedIn
protected void Login1_LoggedIn(object sender, EventArgs e) { Response.Redirect("nuevaUbicacion.aspx"); }
para Curiosos…
Para los curiosos con “El Gran Reflector.NET” nos da luz en las sombras, podremos ver como lo obtiene y ver como funciona algunos parámetros
Friend Shared Function GetReturnUrl(ByVal useDefaultIfAbsent As Boolean) As String FormsAuthentication.Initialize Dim current As HttpContext = HttpContext.Current Dim str As String = current.Request.QueryString.Item("ReturnUrl") If (str Is Nothing) Then str = current.Request.Form.Item("ReturnUrl") If ((Not String.IsNullOrEmpty(str) AndAlso Not str.Contains("/")) AndAlso str.Contains("%")) Then str = HttpUtility.UrlDecode(str) End If End If If ((Not String.IsNullOrEmpty(str) AndAlso Not FormsAuthentication.EnableCrossAppRedirects) AndAlso Not UrlPath.IsPathOnSameServer(str, current.Request.Url)) Then str = Nothing End If If (Not String.IsNullOrEmpty(str) AndAlso CrossSiteScriptingValidation.IsDangerousUrl(str)) Then Throw New HttpException(SR.GetString("Invalid_redirect_return_url")) End If If ((str Is Nothing) AndAlso useDefaultIfAbsent) Then Return FormsAuthentication.DefaultUrl End If Return str End Function
En C# (para los que no le gusta leer Dim)
internal static string GetReturnUrl(bool useDefaultIfAbsent) { Initialize(); HttpContext current = HttpContext.Current; string str = current.Request.QueryString["ReturnUrl"]; if (str == null) { str = current.Request.Form["ReturnUrl"]; if ((!string.IsNullOrEmpty(str) && !str.Contains("/")) && str.Contains("%")) { str = HttpUtility.UrlDecode(str); } } if ((!string.IsNullOrEmpty(str) && !EnableCrossAppRedirects) && !UrlPath.IsPathOnSameServer(str, current.Request.Url)) { str = null; } if (!string.IsNullOrEmpty(str) && CrossSiteScriptingValidation.IsDangerousUrl(str)) { throw new HttpException(SR.GetString("Invalid_redirect_return_url")); } if ((str == null) && useDefaultIfAbsent) { return DefaultUrl; } return str; }
Enlaces
- Login.LoggedIn (Evento)
Aparece cuando el usuario inicia sesión en el sitio Web y se ha autenticado.
http://msdn.microsoft.com/es-es/library/system.web.ui.webcontrols.login.loggedin(VS.80).aspx