Friday, October 5, 2012

An issue with the localhost in Windows....

/localhost is not working but /127.0.0.1 is

This week i faced a problem. While working on the ASP.NET platform i encountered that my

web pages were not running while debugging. It was showing this error (see the image below) .
error page view

It was actually working last night what happened all of a sudden. Some had one suggested me to set the page as default page and run it, still the same error persisted .Then i went back and tried running the default page that .NET provided while creating a new ASP.NET project. Still the 404 sort error didn't leave me alone . How could this happen???

I tried loading my page int the IIS, lo-and-behold the error is in no mood to leave me. I tried loading a Simple HTML page onto the IIS ,it too didn't work. That's when i realised the error was not being generated due to .NET it was something else. Every thing was actually working properly the day before. How could this happen in just a night's time .....
[For those who don't know how to use IIS simply refer my next post.. ]

I started searching the internet for the possible solutions.
The first one i stumbled upon was the ip 127.0.0.1 I tried replacing /localhost with /127.0.0.1

i.e. when we browse through the IIS servers when the browser opens  i replaced this

http://localhost/test/home.html
with  http://127.0.0.1/test/home.html
hurray :D  the web page was working
that means the localhost mapping was wrong or missing. I tried the same thing again with the

.NET platform too, there too it worked....
Now i started to search for a solution to this to get the mapping right as i suppose the problem would be.....
While searching i saw that the same problem occurs on many people's PC and different solutions work on different PC's. Here in i'm listing them...

1.) Some firewall or antivirus blocking software setting.

2.) IE-->Tools-->Options--> Connection --> LAN Settings Check Bypass Proxy for local addresses

3.) Check the host file used by the OS
remove--> ::1 localhost
set--> 127.0.0.1 localhost 
[you can find the host file in --> /WINDOWS/system32/Drivers/etc /hosts
or in some versions  it is located in--> /Windows/i386/hosts]

4.) Try reinstalling the IIS

5.) Restore the Computer to a previous restore point.

The Options 2 and 3 worked in most cases but in my case none worked :( may be my bad luck. Still i'm searching for a probable solution for my case but till then i atleast have a temporary resolve and can work on my projects though with a little tediousness by replacing /localhost with /127.0.0.1  but it's getting a bit tiresome by repeating the same thing every time i debug a page.

Usually what i used to do instead of wasting this lot of time searching for the solution is just reinstall the OS..... but that is not a probable solution this time cause i have some important DB on which i'm currently working..
I suppose this error had crept up because i uninstalled some networking softwares that i had installed previously installed in my PC.
I hope this post will be useful to someone who will come across the same sort of errors..... and hope that someone could help me as well :)

UPDATE
(Oct 9, 2012)
This time i tried some thing extra..... I downloaded host files from my friends. Though after replacing none of them solved my problem, What i noticed was my host file was of 426kB while theirs' were hardly of 1kB.(My local host had thousands of entries as compared to the normal ones where there are hardly 8-10 entries.) In short my host file was corrupted but i also realized that some other files too might have got corrupted, which might caused this problem to arise.

UPDATE (October 10,2012)
Hurray!!...My localhost is working perfectly fine now.. :D :D What did I do Significant for this turn around to happen??
I just happened to run the Spybot Search and Destroy2 software and now it's working perfectly fine!! Dunno what logic went behind it but my job's done.....now i can host and debug pages with ease..
Now i can rest in peace with my local host... :D

                                                    The author is a computer engineering student and a budding programmer

4 comments:

  1. Sir u said that the problem might have crept in due to uninstallation of some networking softwares,so why dont u restore ur computer & then install those networking softwares & then see that if its working....This might not be the probable solution because i dont have knowledge about ASP.NET & IIS

    ReplyDelete
    Replies
    1. first thing.....don't call me sir. I'm still a student :D
      second thing
      when i tried for system restore what i found was System Restore was turned off for all my drives.... bit strange but that is what it was, it could surely have corrected the problem. and about installing that software again I'll look to it that i won't ever install that software again... I uninstalled it cause other than it being useless(I've found some better alternatives for that ware) I was also short on disk space..

      Delete
  2. Hey Reese..
    Try this..

    1)Go to "C:/Windows/System32/drivers/etc"
    Open hosts file in notepad..

    2)Repace..
    "# 127.0.0.1 localhost"
    With
    "127.0.0.1 localhost"
    (Just remove # & Spaces...)

    ReplyDelete
    Replies
    1. Yup Junaid..
      Tried that actually i had tried this previously...
      but when i opened the host file it was found exactly as it is required... i mean there weren't any errors there, yet i tried some changes with Spaces tabs and stuffs like that no changes though..!!!

      Delete