0

I'm trying to set a variable to the current URL using:

Dim url As String = HttpContext.Current.Request.url.AbsoluteUri

Which is returning:

http://localhost/xxxxx2015/xxxx.asmx/xxxx

This seems to be the file name followed by the web function name.

What it's supposed to return/what it's displaying in IE is:

http://localhost/xxxxx2015/Default.aspx?form=xxxx

Why is this?

Bugs
  • 4,491
  • 9
  • 32
  • 41
Nick
  • 71
  • 2
  • 12
  • Check this answer from Muhammad Omar ElShourbagy: http://stackoverflow.com/a/15002973/3428749 – Nuno Ribeiro Mar 29 '17 at 13:55
  • Are you within a web service when you call this code? Or are you within an ASPX form? Your question lacks context. – mason Mar 29 '17 at 13:58
  • You might try: HttpContext.Current.Request.Url.OriginalString http://blog.jonschneider.com/2014/10/systemuri-net-framework-45-visual-guide.html – SLWS Mar 29 '17 at 13:58
  • 1
    @NunoRibeiro - I've already looked at his post and it didn't help me. – Nick Mar 29 '17 at 14:02
  • @mason - Web Service. – Nick Mar 29 '17 at 14:03
  • @SLWS - still returning the same url as above. – Nick Mar 29 '17 at 14:03
  • You are expecting Web Form URL to be returned by `HttpContext.Current.Request.url.AbsoluteUri` when you are in context of Web Service ? How's that possible ? Are you making an Ajax call to web service from aspx page and you are trying to get the URL of web form in the web service ? – Chetan Mar 29 '17 at 14:08

1 Answers1

1

You are apparently in a WebRequest, so the current request is the request for that method. However, it is sent from some page, so possibly a "referrer" is set with the URL you are looking for.

See Getting the HTTP Referrer in ASP.NET for more details on how to get it. Basically: use Request.UrlReferrer

Community
  • 1
  • 1
Hans Kesting
  • 38,117
  • 9
  • 79
  • 111