Get the URL from the local website server

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Fredrik Kacsmarck Fredrik Kacsmarck 4 months ago.

  • Author
    Posts
  • #64507
    Profile photo of Fredrik Kacsmarck
    Fredrik Kacsmarck
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    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
    Profile photo of Fredrik Kacsmarck
    Fredrik Kacsmarck
    Participant

    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
    Profile photo of Fredrik Kacsmarck
    Fredrik Kacsmarck
    Participant

    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
    Profile photo of Fredrik Kacsmarck
    Fredrik Kacsmarck
    Participant

    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.