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?

8
  • 2
    hosts file can't map port to host. So it is better if you change http://localhost:xxxx to https://localhost:xxxx without changing host file and then open https://localhost:xxxx Commented Dec 28, 2015 at 7:17
  • @AbdulRaufMujahid So its better if I change localhost:xxxx to localhost:xxxx ??? Commented Dec 28, 2015 at 7:19
  • 1
    @RehanKhan just be sure your port isnt using already. Commented Dec 28, 2015 at 7:21
  • @RehanKhan yes change http://localhost:xxxx to https://localhost:yyyy Commented Dec 28, 2015 at 7:23
  • 1
    useful information check this out stackoverflow.com/questions/4709014/… Commented Dec 28, 2015 at 7:27

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

2 Comments

do you mean [RequireHttps] rather than [RequireHttp]? Please correct it in your code if thats true.
@RehanKhan, Yes, it is RequireHttps not RequireHttp.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.