How to access the site using domain name instead of localhost in IIS
Srinivas
Wednesday, September 24, 2014
Domain name IIS
,
Domain name instead of localhost
,
IIS
,
IIS 8
4 comments
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 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 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
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.
#2. Expand the Server node and click on Sites folder.
#3. Click on Add Website in Actions pane.
Note: If need any help for the above steps then please check my previous post How to setup basic website in iis 8.
#4. Enter the details in the Add Website window as follows.
#3. Click on Website that you want to access using domain name and then click on Bindings in the Actions pane.
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 google address.
#5. Now do the change in hosts file as we did in #6 in case 1.
#6. Once done this change you can access your local website with google address.
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 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 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
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.
#2. Expand the Server node and click on Sites folder.
#3. Click on Add Website in Actions pane.
Note: If need any help for the above steps then please check my previous post How to setup basic website in iis 8.
#4. Enter the details in the Add Website window as follows.
#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 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 do the following changes.
(add " 127.0.0.1 www.testsite.com " to hosts file)
Now try to reload the page by clearing the browser cache. It will work as follows.
Case 2:
If you want to access the website using domain name which is created already then follow the below steps.
#1. Open IIS.
#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.
#4. Select the binding of type http and then click on Edit. This will open a new window as follows.
I am entering this as www.google.com because i want to access my site with google address.
#5. Now do the change in hosts file as we did in #6 in case 1.
#6. Once done this change you can access your local website with google address.
Note: The changes that you are doing in hosts files are applicable to that particular local machine in which that file exits.
Subscribe to:
Post Comments
(
Atom
)
Quite informative...
ReplyDeleteGreat thanks but I can't view the site on another device. Only the server PC displays the site. Do I need to configure something else? Please advice.
ReplyDeleteGreat thanks but I can't view the site on another device. Only the server PC displays the site. Do I need to configure something else? Please advice.
ReplyDeleteWhenever 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
ReplyDeletehow-to access host file