0

I work with a legacy ASP.NET web application that has URLs that use query string values to pass information between pages. I ran into an issue with a couple of URLs that contain spaces, numbers, and dashes that I'm trying to understand.

Here's an example of the URL:

http://myserver.com/SelectReport.aspx?Name=My Report&ReportFile=my_financial_report&ReportTitle=My Financial Planning Across A 1-Year Or 2-Year Outlook

The problematic part of the URL is the ReportTitle query string value.

When I click the link in Internet Explorer 11 or Microsoft Edge, I get a Cant' reach this page. It took too long to connect to this website. Error Code: INET_E_CONNECTION_TIMEOUT error. It should be noted that the link works fine if I turn ON compatibility view settings in Internet Explorer 11.

When I click the link in Google Chrome, I get a `This site can't be reached. The connection was reset. ERR_CONNECTION_RESET" error.

If I delete the 2 in 2-Year, the link works. However, if I delete the 1 in 1-Year and leave 2-Year alone, the link does not work. I'd like to know why removing the 2 in 2-Year allows the link to work, but removing the 1 in 1-Year does not. This is true whether I replace spaces with %20 or not. Does anyone know the answer?

I know that I can replace the spaces in the ReportTitle query string value with plus signs (+) and it will work. This is likely the route I will take to fix the issue, but I was hoping to understand the issue better.

Thanks!

user2063351
  • 503
  • 2
  • 13
  • 31
  • By the way query parameters should be separated by `&' instead of `?` except for the first one. – fiveelements Aug 13 '19 at 16:31
  • My mistake @fiveelements. I'll edit the post and fix that. – user2063351 Aug 13 '19 at 16:32
  • That's fine. However, I have tried this URL in various browsers with my domain as target and I do not get an error. `-` is considered a safe character in URL. Empty spaces are invalid in URL and hence replaced by `%20` by the browser or you can manually replace it by `+`. Both are same. Your last two paragraphs are confusing. You are saying `%20` does not work but `+` would work. Please clarify. Refer this [Safe characters in URL](https://stackoverflow.com/questions/695438/safe-characters-for-friendly-url) – fiveelements Aug 13 '19 at 16:48
  • In the web application, the link is generated in code. If I replace the spaces with "%20" in the code that generates the link, publish the code, then click the link, the page still times out. If I replace the spaces with "+" in the code, publish it, then click the link, the link works without timing out. If the `ReportTitle` value contains something like, `1-Year or 2-Year`, where a number followed by a dash is later followed by another number and a dash, the link does not work. If I remove the `2` in that example so it says `1-Year or -Year`, the link works for some reason. – user2063351 Aug 13 '19 at 17:35
  • Is there some sort of URL encoding/decoding happening in code that generates the link? Would you please try putting these URLs in a plain static HTML and try (with `spaces` as is, with `%20` replacing spaces and with `+` replacing spaces). – fiveelements Aug 13 '19 at 18:21

1 Answers1

0

This is the continuation of my comments in the original post. I am writing this answer to share the demo example. It may not be a full answer.

There is absolutely no difference when you have spaces, or spaces are replaced by %20 or spaces are replaced by +. Also, I mentioned earlier your URL has valid characters including -.

See the three links below. I suspect it is your application that is dealing with URL encoding, decoding and having issues. It is not a general problem.

<a href="http://stackoverflow.com?Name=My Report&ReportFile=my_financial_report&ReportTitle=My Financial Planning Across A 1-Year Or 2-Year Outlook">With Spaces</a>
<br>
<a href="http:///stackoverflow.com?Name=My%20Report&ReportFile=my_financial_report&ReportTitle=My%20Financial%20Planning%20Across%20A%201-Year%20Or%202-Year%20Outlook">With %20</a>
<br>
<a href="http:///stackoverflow.com?Name=My+Report&ReportFile=my_financial_report&ReportTitle=My+Financial+Planning+Across+A+1-Year+Or+2-Year+Outlook">With +</a>
fiveelements
  • 3,649
  • 1
  • 17
  • 16