How do you force IIS Express to default to https URL? - asp.net-mvc

I have enabled SSL in my MVC website for IIS Express by setting 'Enable SSL' in the project properties to true. So now I can access my site while debugging over http as well as https (IIS Express's default port 44300). However I'd like to force the default URL to be the SSL one. https://localhost:44300/. Whenever I run the app. from VS it always loads the http URL.
If I try and update the project URL (right click on the project -> click on properties -> navigate to the web tab -> set project URL to https://localhost:44300/) to https, the website fails to load. I just get a 'Page could not be loaded' error in the browser. However if I explicitly add a binding for https to port 44300 in my local IIS instance using IIS Management service it seems to work. I don't think I should have to touch local IIS in any way though.
Am I missing something here? Could someone help me figure this out?

The core of this seems to be finding the applicationhost.config file being passed to IIS, find the section like
<bindings>
<binding protocol="http" bindingInformation="*:62858:localhost" />
and change http to https
If you're using the Rider IDE, open the project properties (right click on solution explorer's icon for the project).
Make sure you add a port number for "SSL" and switch the Url from http://... to https://...
The port must be between 44300 and 44398, otherwise you'll get a connection reset error (see https://stackoverflow.com/a/24957146/423033 )

Sudeep,
If you are using the IIS on your machine (or on your server) you could create a rewrite rule that would intercept any http requests and will replace the http protocol with https.
Here is a link to get you started: http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
As for IIS Express, it has its advantages of using it, but on the other side it is missing advanced functionality like URL Rewrite (check this link: http://weblogs.asp.net/scottgu/introducing-iis-express).
Best Regards,
Daniel D.

Figured it out. This tutorial is perfect and walks you through the whole process
http://www.lansweeper.com/kb/54/How-to-configure-SSL-in-IIS-Express.html

Related

Remove the custom port number from https url using IIS

I have a site which is configured in IIS7. Currently, the site named Site1, which uses the https protocol with a custom port number 5001. I can access this site by using the url given below:
https://demo.mydomain.com:5001/Site1
I need to eliminate the port number from the url, but it should access the same content which is used by the url "https://demo.mydomain.com:5001/Site1".
Expected result should be like this: "https://demo.mydomain.com/Site1"
Any help is much appreciated.
In IIS Manager, click on the Site (left pane) and the click Bindings (right pane). You'll see a binding for port 5001. Edit that binding to be port 443. (https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/bindings/binding)
My guess though is you have some other site that is bound to port 443, if that is the case you either need to remove it from the other site, or if you need them to coexist, you need to dig into SNI which is a bit more advanced topic (SNI and SSL on IIS 8.5)

ASP.NET MVC RequireHttps Page Not Found

I am trying to add the RequireHttps tag to a controller action but when I try to navigate to it I get a page not found error when I try:
https://localhost/MVCDemo3_4/Home/Index2
or
http://localhost/MVCDemo3_4/Home/Index2
The Http one tries to redirect to HTTPS but then the HTTPS can't find the page.
It depends more on how this is being hosted than the MVC attribute. If it's running off of a real IIS (or other full httpd) server on locahost, then you just need to make sure IIS is listening on both 80 and 443 (as #Jester mentioned, check the bindings). However, if you are using IIS Express via Visual Studio, then you really can only listen on one port and your debugging needs to be either all non-SSL or all SSL. This is controlled through the propeties on the Web project. Look at the Project URL field.

asp.net core RC2 iis hosting

I have hosted asp.net core app in IIS on window server 2012 R2 Standard. My site works fine when I use localhost based URL on the machine but when I try to access the URL using host name/machine name from network computer it does not work. What do I need to do to make it accessible from other computers?
There can be different reason for this:
Check your firewall to make sure your port 80 is open.
Check that the hostname point to the IP URL of your server.
What is the http code returned by the it does not work?
Tool:
Enter the Domain and IP, make sure they point to the same place.
http://www.hcidata.info/host2ip.htm
If firewall isn't the problem, and the site works via localhost on the server, make sure your IIS bindings are correct. Right click site, edit bindings, verify the domain / ip / etc match how you're trying to access it.

MVC WebApplication no longer starts in IIS Express (redirects to https://localhost in Chrome)

I was changing OAuth/Owin settings and Azure publish settings in a Web Application project this morning, but soon after we decided deployment will be to a specific IIS Azure VM (now visible across our local domain). All code/setting changes have been reverted.
At one point I also changed the drivers\etc\hosts file to allow a dummy name for Microsoft OAuth, but that has been reverted.
Notes:
My startup URL is http://localhost:22222/
I am running under IIS Express (as my local Dev VM will not allow me to install full IIS)
When I start the Web Application with IE I simply get "This page can't be displayed"
If I start it with Chrome I get "This webpage is not available", but it also changes the browser URL to https://localhost (note the s, i.e. using SSL).
I have pulled the project down fresh from source control. No change.
The project is under TFS source control.
Another developer on the same project has the latest files and it works fine.
If I run any other Web Application project, they work just fine.
All OWIN registration of providers has been commented out. No change.
Deleted the entire project folder and pulled fresh from TFS. No change. This probably means a local machine setting somewhere is the cause?
What could I have damaged in my Web Application to cause this problem? I have been scratching my head for hours now and nothing we try is working. The application simply will not start in any browser.
Project Web Settings tab:
Answer at bottom, given to this chromium issue [issue 444479] helped me:
Same here - I also believe caused by HSTS - see
http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
If you have (developed) any other localhost sites which send a HSTS
header...
eg. Strict-Transport-Security: max-age=31536000; includeSubDomains;
preload
...then depending on the value of max-age, future requests to
localhost will be required to be served over HTTPS.
To get around this, I did the following.
In the Chrome address bar type "chrome://net-internals/#hsts"
At the very bottom of a page is QUERY domain textbox - verify that localhost is known to the browser
If it is, DELETE the localhost domain using the textbox above
Your site should now work using plain old HTTP
HTH,
Jay
ps. This is not a permanent solution, but will at least get it working
between projects. If anyone knows how to permanently exclude localhost
from the HSTS list please let me know :)
Give it a try.

IIS Site Bindings

I have a web website in IIS 6.1, with a Self-signed SSL. The website contains 3 web applications, all setup to use https as binding. Whenever I browse the application, the URL shows as
https://localhost/mysite1/default.aspx
I was under the impression that by adding a Site binding to use the computer name instead would change the URL to something like:
https://myservername/mysite1/default.aspx,
which means it will no longer complain about the SSL certificate being invalid when accessing the website, as the SSL is issued by "myservername"
I used the following command:
cscript.exe //nologo %systemdrive%\inetpub\adminscripts\adsutil.vbs set W3SVC/2/SecureBindings “:443:myservername”
My application identifier (2), which is shown under the "Sites" node.
After running the command, the URL is now directing to:
https://myservername.xn--9o0a/mysite1/default.aspx
That obviously doesn't work... it added .xn--9o0a to the URL??? What am I missing?
After doing some googling I managed to find this article that explains everything and how to fix the issue I was having.
http://gavinmckay.wordpress.com/2009/03/24/howto-fix-wcf-host-name-on-iis/

Resources