Click here to Skip to main content
14,550,995 members

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

Rate this:
5.00 (3 votes)
Please Sign up or sign in to vote.
5.00 (3 votes)
7 Oct 2014CPOL
How to access the site using domain name instead of localhost in IIS


Whenever we host any website in IIS (Internet Information Services), we used to access the website with localhost or with that particular machine IP address in the way of http://localhost/TestSite/TestPage.aspx.

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

How can I tell my IIS that is pointing to the files on my local computer not try to access the internet?

The answer behind all these questions is Hosts file.

This will be in <Windows Root Folder>\System32\Drivers\etc\. In general, for the people who used to install Windows Operating System in C drive 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:

Image 1

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

Case 1

If you want to create a new website which is possible for accessing through domain name, follow the below steps:

  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 Sites folder.
  3. Click on Add Website in Actions pane.

    Note: If you need any help for the above steps, then please check out my blog post - How to setup basic website in iis 8 .

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

    Image 2

  5. Click on Ok to create website.


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

    This is because the address you entered is going to search in the internet instead of your localhost. To overcome this, open the Hosts file in any text editor and make the following changes:

    (add " " to hosts file)

    Image 3

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

    Image 4

Case 2

If you want to access the website using domain name which is created already, then follow the below steps.

  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 Website that you want to access using domain name and then click on Bindings in the Actions pane.

    Image 5

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

    Image 6

    Enter the host name in the provided text box. I am entering this as because I want to access my site with Google address.

  5. Now make the change in hosts file as we did in 6 in case 1.

    Image 7

  6. Once you have made this change, you can access your local website with google address.

    Image 8

    Note: The changes that you are making in hosts files are applicable to that particular local machine in which that file exists.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sri Nivas.M
Software Developer
India India
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Pratik Bhuva7-Oct-14 21:26
professionalPratik Bhuva7-Oct-14 21:26 
GeneralRe: My vote of 5 Pin
Sri Nivas.M7-Oct-14 21:31
MemberSri Nivas.M7-Oct-14 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 7 Oct 2014

Tagged as


7 bookmarked