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

Posted on 2012-09-20
Last Modified: 2012-09-23
I am using the following code to determine the web url so I can generate an e-mail to the user.


The problem is that its suppose to return something like:

but it is returning instead (via e-mail)


Any idea why and how to resolve?
Question by:CipherIS
    LVL 8

    Expert Comment

    Could you show me the url on the address bar of your browser ? Which IIS did you deploy your website on ?
    LVL 1

    Author Comment

    Can't show you the url on the address bar.  IIS6
    LVL 22

    Assisted Solution

    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


    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 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.
    LVL 8

    Accepted Solution

    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.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now