How to remove returnurl from url?

前端 未结 10 655
梦谈多话
梦谈多话 2020-11-28 08:54

I want to remove \"returnurl=/blabla\" from address bar when a user want to access to a login required page. Because I\'m trying to redirect the user to a static page after

10条回答
  •  春和景丽
    2020-11-28 08:58

    You can use the HttpUtility.ParseQueryString to remove that element. If you use VB.NET then this code does this

    Dim nvcQuery As NameValueCollection
    Dim strQuery As String = ""
    
    If Not IsNothing(Request.QueryString("ReturnUrl")) Then
        If Request.QueryString("ReturnUrl").Length Then
            nvcQuery = HttpUtility.ParseQueryString(Request.QueryString.ToString)
            For Each strKey As String In nvcQuery.AllKeys
                If strKey <> "ReturnUrl" Then
                    If strQuery.Length Then strQuery += "&"
                    strQuery += strKey + "=" + nvcQuery(strKey)
                End If
            Next
            If strQuery.Length Then strQuery = "?" + strQuery
            If Request.CurrentExecutionFilePath <> "/default.aspx" Then
                Response.Redirect(Request.CurrentExecutionFilePath + strQuery)
            Else
                Response.Redirect("/" + strQuery)
            End If
            Response.Write(Server.HtmlEncode(strQuery))
        End If
    End If
    

    I would put this in the Page.Init event - obviously you will need to change the "/default.aspx" to match the URL of your login page.

提交回复
热议问题