1

My request URL is: http://domain.com/some/path%2Fescaped.

I want to retrieve this exact URL. I do NOT want it decoded, like http://domain.com/some/path/escaped; I want it encoded like http://domain.com/some/path%2Fescaped.

How do I get this URL? I have tried Request.Path, Request.RawUrl, Request.Url.AbsoluteUri, Request.Url.OriginalString...each provide the URL decoded, like http://domain.com/some/path/escaped.

I can get this in PHP with $_SERVER["REQUEST_URI"].

Chad Johnson
  • 21,215
  • 34
  • 109
  • 207

3 Answers3

1

You need Request.Url.OriginalString;

Taryn
  • 242,637
  • 56
  • 362
  • 405
Daf
  • 11
  • 1
0

I don't know if this is going to work or not, but have you already tried Server.URLDecode or Server.URLEncode?

jaressloo
  • 210
  • 3
  • 13
  • Unfortunately this is a non-solution, as this encodes the entire URL, subsequently encoding all instances of "/", including actual path separators. – Chad Johnson Apr 26 '12 at 23:29
0

Javascript call document.location.href should return the expected format. Here is a suggestion; Check if this works for you.

1) have a hidden variable

<input type="hidden" id="hdn" runat="server" />

2) Set hidden variable using javascript function

function setURL() {
        document.getElementById("hdn").value = document.location.href;
    }

3) on server side

Page.ClientScript.RegisterStartupScript(this.GetType(),
        "setURL", "setURL();", true);

4) read hidden variable value at server side (which is the URL in actual format)

hdn.Value
Prashanth Thurairatnam
  • 4,353
  • 2
  • 14
  • 17