How to Access the Site Using Domain Name Instead of localhost in IIS

Whenever we host a website in Internet Information Services (IIS), we previously would access the website with localhost or with that specific machine IP address in the manner of: http://localhost/TestSite/TestPage.aspx

Did you ever think of accessing your website with a domain name, such as http://www.testsite.com, instead of http://localhost/testsite or http://127.0.0.1/testsite on your local machine?

How can I tell my IIS that http://www.testsite.com is pointing to the files on my local computer and to not try to access the internet?

The answer behind all these questions is the Hosts file.

This will be in <Windows Root Folder>\System32\Drivers\etc\. In general if the Windows Operating System is installed in the C drive then it will be C:\Windows\System32\drivers\etc. You can open this file in Notepad, Notepad++ or any text editor that you have. If you open this file, it will be as follows.

local host

Note: You need administrator privileges to save your changes in this file.

Case 1

If you want to create a new website then that is possible for accessing using a domain name. Use the following procedure.

  1. Open IIS (Click WIN+R, enter inetmgr in the dialog and click OK. Alternatively, search for IIS Manger in start window).

  2. Expand the Server node and click on the Sites folder.

  3. Click on Add Website in the Actions pane.

    Note: If need any help for the preceding procedure then please check my blog article How to setup basic website in IIS 8.

  4. Enter the details in the Add Website window as follows.

    host name

  5. Click on Ok to create the website.

  6. If you try to browse your website now, you will see an alert in Chrome that your webpage is not available. You will see the same kind of issue in other browsers also.

    This is because the address you entered will search in the internet instead of your localhost. To overcome this open the Hosts file in any text editor and add the following command.

    127.0.0.1 www.testsite.com

    testsite

    Now try to reload the page by clearing the browser cache. It will work as follows.

    home page

Case 2

If you want to access the website using the domain name you created then use the following procedure.

  1. Open IIS (Click WIN+R, enter inetmgr in the dialog and click OK. Alternatively, search for IIS Manger in start window).

  2. Expand the Server node and then expand Sites folder.

  3. Click on the Website that you want to access using a domain name and then click on Bindings in the Actions pane.

    binding

  4. Select the binding of type http and then click on Edit. This will open a new window as follows:

    edit in hostname

    Enter the host name in the provided text box.

    I am entering this as www.google.com because I want to access my site with a Google address.

  5. Now make the change in the hosts file as we did in #6 in case1.

    chang in host file

  6. After having made this change you can access your local website with the Google address.

    *modify this template

    Note: The changes you are making in the hosts files are applicable only to that specific local machine in which the file exits.


Similar Articles