Get the URL from the local website server

This topic contains 4 replies, has 2 voices, and was last updated by  Fredrik Kacsmarck 1 year, 5 months ago.

  • Author
  • #64507

    Fredrik Kacsmarck

    Hi all,

    Is there a good way to get the URL of the local web server?
    Checked e.g. Get-Website but it lists the local path and so on, not the URL.
    Get-WebUrl just lists http:/localhost which doesnt work.

    The scenario is that I would like to be able to get the URL from the server the script is running on.
    So that I can use a variable in the scripts instead of hard-coding the URL.

    I guess a workaround is to add an environment parameter but just wanted to check if I don't have to use that.

    Would like to e.g. "Get URL from 'default web site' "

    Thanks in advance.

  • #64609

    Daniel Krebs

    Have you specified a host header in the bindings of the Default Web Site?

    If not, IIS can't really know the name of the website you've registered in DNS. In other words, IIS will respond to any request which doesn't match the binding of other websites hosted on the same server.

  • #64791

    Fredrik Kacsmarck

    Ah, didn't think about that.
    It was not set on the servers and since I need to add that configuration I may as well just configure the environment variable.

    Thanks for the answer.

  • #64681

    Fredrik Kacsmarck

    Ah that explains it, didn't think about that.
    Then it's about the same amount of "work/configuration", either variable or host header 🙂

  • #64684

    Fredrik Kacsmarck

    Not sure if this will become a double post (previous response disappeared).

    Anyway, didn't think about the host header configuration.
    Then it's about the same amount of "work/configuration", either environment variable or IIS config.

You must be logged in to reply to this topic.