Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can forms authentication ignore returnUrl

Is there an easy way to get forms authentication to ignore the returnURL?

So the user clicks a link, the site timesout, they get redirected to my login page (which appends ReturnUrl to the URL) - I don't want this to happen, or for it to be ignored when they login again.

like image 983
ozz Avatar asked May 12 '11 08:05

ozz


2 Answers

One option is to have some code in your login form's code-behind that does the following:

if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
{
    Response.Redirect("path/to/my/login.aspx");
}

In other words, check in your login page for the presence of the returnUrl querystring parameter and if it's present, strip it out by redirecting back to yourself.

like image 160
Rob Avatar answered Sep 30 '22 03:09

Rob


You can strip it off if you don't want to show it. I do that because I don't want it to show with SEO-friendly URLs that I have setup.

In the Global.asax file put the following:

Protected Sub Application_EndRequest(sender As Object, e As System.EventArgs)

        Dim redirectUrl As String = Me.Response.RedirectLocation
        If Not Me.Request.RawUrl.Contains("ReturnUrl=") AndAlso Not String.IsNullOrEmpty(redirectUrl) Then
            Me.Response.RedirectLocation = Regex.Replace(redirectUrl, "\?ReturnUrl=(?'url'[^&]*)", String.Empty)
        End If

End Sub
like image 41
Ira Rainey Avatar answered Sep 30 '22 01:09

Ira Rainey