I found the issue with FormsAuthentication.GetRedirectUrl when it redirects then it redirects with the first querystring that you have while in fact you might have more than one querystring
e.g http://localhost/myweb/login.aspx?returnurl=myview.aspx?viewID=123&viewname=abc&viewall=false then the standard FormsAuthentication will redirect to http://localhost/myweb/myview.aspx?viewID=123
but where’s the remaining viewname querystring and viewall querystring??to fix this, just use the code below to pick the remaining querystring
Methods:
'this is used to fix the issue with FormsAuthentication.GetRedirectUrl only pick the first query string 'get the original Redirect URL Dim redirectUrl As StringBuilder = New StringBuilder(FormsAuthentication.GetRedirectUrl(" ", True)) Dim coll As NameValueCollection = objRequest.QueryString 'iterate through every key in query string 'add the missing query string For Each key As String In coll.AllKeys If (String.Compare(key, "returnurl", True) 0) Then Dim values As String() = coll.GetValues(key) If (values.Length > 0) Then Dim pair As String = String.Format("{0}={1}", key, values(0)) If (redirectUrl.ToString().IndexOf(pair) < 0) Then redirectUrl.Append("&" + pair) End If End If End If Next 'this is to retain the original URL as in the query string objResponse.Redirect(redirectUrl.ToString())
Leave a Reply