Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3790
  • Last Modified:

C# HttpContext.Current.Request.Url.AbsoluteUri.ToString()

I am using the following code to determine the web url so I can generate an e-mail to the user.

HttpContext.Current.Request.Url.AbsoluteUri.ToString()

The problem is that its suppose to return something like:

https://www.microsoft.com/mywebiste/default.aspx

but it is returning instead (via e-mail)

https://myservername/mywebsite/default.aspx

Any idea why and how to resolve?
0
CipherIS
Asked:
CipherIS
  • 2
2 Solutions
 
vinhnlCommented:
Could you show me the url on the address bar of your browser ? Which IIS did you deploy your website on ?
0
 
CipherISAuthor Commented:
Can't show you the url on the address bar.  IIS6
0
 
ambienceCommented:
Most likely the url is because you are testing on a dev machine and the request url (that you can not show) is of the form

https://myservername/...

In general it is better not to rely on the Request.Url to use in emails, because the request url can take many forms. It may just return http://xxx.xxx.xxx.xxx if the user types in an IP address. It is better to use a config file to store the base address that you can prepend to relative resource URI to form an absolute URL.
0
 
vinhnlCommented:
Hi cipheris,

I ask you that beacause this method returns directly the url in the address bar of your browser. Like ambience explained, if you type https://myservername/mywebsite/default.aspx, the method HttpContext.Current.Request.Url.AbsoluteUri.ToString() will return the local address. Store domaine address in config file is a better solution.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now