0

I am testing SSL Encryption on my local PC which requires me to change my ASP.MVC Project URL from http://localhost:xxxx to something like http://payroll.net:81. When I run this application, ASP.MVC is probably not loading the project on this URL. Browser is giving the following error:

The server at payroll.net can't be found, because the DNS lookup failed. DNS is the network service that translates a website's name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing Google Chrome from accessing the network.

I have to mention that I have updated hosts file in ../WINDOWS/System32/drivers/etc/ location as:

127.0.0.1 payroll.net:81.

I also have to mention that if I run the same project under default Project URL that IISExpress uses i.e., http://localhost:xxxx, project runs all good. Any idea on how this project can be run with http://payroll.net:81 URL on IISExpress?

Bart
  • 9,925
  • 7
  • 47
  • 64
Jogi
  • 1
  • 2
  • 14
  • 29

3 Answers3

2

hosts file can't resolve IP addresses to hostname if port is specified with the IP address. So

127.0.0.1 payroll.net:81 is wrong

and

127.0.0.1 payroll.net is correct

Now you can safely open https://payroll.net:81. (which now automatically maps to https://localhost:81) Just make sure the site is hosted on IISExpress on port 81 and ssl is enabled

Additional Notes:

The point I wanted to demonstrate in my first comment was that SSL testing does not require you to change your url from http://localhost:xxxx to https://payroll.net:81 (As mentioned in your question). For SSL testing. you can just host your site to any different unused port without changing hosts file e.g https://localhost:91

Source:

My comments and their verification in Rehan Khan's answer

Abdul Rauf
  • 5,798
  • 5
  • 50
  • 70
  • 1
    One can also learn that ports are not to be configured in the `dns alias file` (`hosts`) and they are to be configured only on IISExpress (or any other equivalent server) and in your application. So `dns alias file` function is to only resolves ip addresses to hostnames. Opening and closing of ports is application server's job. (Server-Client Architecture). `IISExpress` being the `Server` and our `MS Visual Studio Application` as `Client`. – Jogi Dec 29 '15 at 10:13
1

If you want to run your web application using https, just add the attribute '[RequireHttps]' to your controllers.

If you have two controllers called HomeController.cs and ActionController.cs, then add this attribute to both the controllers like,

[RequireHttps]
public class HomeController : BaseController
{
// Your controller
}

So, when you make a call to the action inside the HomeController it forces the browser to use https.

Abhilash Augustine
  • 4,128
  • 1
  • 24
  • 24
0

With the help from @AbdulRaufMujahid comments, I've managed to solve out the issue and will answer my own question.

hosts file in C:\WINDOWS\System32\driver\etc\ directory doesn't resolve IP addresses to hostname if port is specified with the IP address. As in my case:

127.0.0.1 payroll.net:81 ------> is wrong ----- > specifying port number 81 prevents the resolution of 127.0.0.1(IP) to payroll.net(hostname).

As soon as I removed 81 as:

127.0.0.1 payroll.net ------> is correct

Project started running like a charm. :-) Thank you @AbdulRaufMujahid and everyone who helped.

Jogi
  • 1
  • 2
  • 14
  • 29