When you initially set up IIS Express to enable SSL, it defaults the port to 44300. Unfortunately, when I try to access my site in on https://localhost/
it doesn't work unless I use the port number 44300 - https://localhost:44300/
.
The links are generated using the following:
<%= Html.ActionLink("Index", "Index", "Home", new { @action = "https://" + Request.Hostname + Url.Action("Index", "Home") }) %>
Although an ugly solution, the @action
keyword can override the generated route, but it means that the application would seemingly need to be aware of any non-standard ports (eg 44300).
The problem with that is that I'd be writing something to solve a problem that would only occur in a development environment.
So my question is... How do I change the port to 443 and have IIS Express like it?
Config for my site is below:
<site name="MySite" id="2" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Inetpub\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:" />
<binding protocol="https" bindingInformation=":44300:" />
</bindings>
</site>
Many thanks in advance.
Update:
This question has been answered by Divya over on the IIS forums.
Since I have spent much time on this topic , I would like to share my finding. I am reposting segment from my other post minus the code. Some background and explanation:
==========================================
After researching aroud, I was able to solve this issue with IIS Express and an override of the Controller class's
OnAuthorization
method (Ref#1). I have also gone with the route recommended by Hanselman (Ref#2). However, I was not complete satisfied with these two solutions due to two reasons:OnAuthorization
only works at the action level, not at the controller class levelmakecert
),netsh
commands, and, in order to use port 80 and port 443, I need to launch VS2010 as administrator, which I frown upon.So, I came up with this solution that is quite simplistic with the following conditions:
I want to be able to use the
RequireHttps
attribute at Controller class or action levelI want MVC to use HTTPS when the
RequireHttps
attribute is present, and use HTTP if it is absentI do not want to have to run Visual Studio as administrator
I want to be able to use any HTTP and HTTPS ports that are assigned by IIS Express
I can reuse the self-signed SSL cert of IIS Express, and I do not care if I see the invalid SSL Prompt
=========================================
You can find my solution/code here ==> ASP.NET MVC RequireHttps in Production Only
Create class
And inside your web config add something like this
And then you use it like
Dan answer is right but if you still have problems with configuring IIS Express to serve your website with http and https on standard ports here is nice tutorial that that guide you step by step:
http://www.lansweeper.com/kb/54/How-to-configure-SSL-in-IIS-Express.html
In my case I accidentally deleted IIS Express certificate. I think it is generated the first time you use SSL in Visual Studio (F4 on selected project to get properties window and checking 'SSS Enabled' checkbox). This tutorial guided me how to create certificate and fix it.
This question has been answered by Divya over on the IIS forums.
As noted by others, there are several nice ways of getting your SSL certs.
or (my preferred method):
The port 44300 is sequential: 00 mean that its the first application you have configured as SSL enabled; 01 will be the second one and so on.
Since I also require my website to only work in HTTPS by adding the
[RequireHttps]
global attribute, I had some trouble debugging. When launched, it was automatically redirecting tohttps://localhost/
To fix this problem when debugging a web site, I simply create a new
RequireHttpsAttribute
that specify the portUse this class when debugging only. When deployed to IIS7, you should use Url rewriting to redirect to HTTPS.