1

VB.NET

Response.Redirect(Request.UrlReferrer.AbsolutePath & "?query=1")

This is a working example of how to navigate to the urlreferrer and include a new querystring.

THE PROBLEM

When urlreferrer includes an existing querystring the rendered markup becomes:

url.aspx?existing=1?query=1

The url does not resolve correctly because of the second ? which should instead be &

QUESTION

How to determine if a urlreferrer already has querystring and implement the correct code to accomodate?

SOLUTION

    If (Request.UrlReferrer.OriginalString.Contains("?")) Then
      Response.Redirect(Request.UrlReferrer.OriginalString & "&query=1")
    Else
      Response.Redirect(Request.UrlReferrer.OriginalString & "?query=1")
    End If

AbsoluteUrl does not include querystrings use OrigionalString as referrer.

2 Answers 2

1

A little logic:

If Request.UrlReferrer.OriginalString.Contains("?") Then
   ...
Else
   ...
End If
Sign up to request clarification or add additional context in comments.

6 Comments

I did consider this obvious approach however am wary that a URL may contain a ? not derived from a querystring. What's your thoughts?
Even in encryted strings? Either way aspx? will work 100% thanks man.
well you wouldn't encode/encrypt the URI, you would do that to the querystring parameters.
Fixed the issue but had to use OriginalString instead of Absolute Url to keep querystrings intact.
Thanks appreciate your help. Up vote for me then? :)
|
1

You can check if there is a ? in de Request.UrlReferrer.AbsolutePath:

If (Request.UrlReferrer.AbsolutePath.Contains("?")) Then
   Response.Redirect(Request.UrlReferrer.AbsolutePath & "&query=1")
Else
   Response.Redirect(Request.UrlReferrer.AbsolutePath & "?query=1")
End If

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.