Having problems using IIS Express SSL with VS2012

2019-03-12 04:29发布

The Problem:

ADFS2 requires that a RP Trust uses https. The RP trust being https://localhost:44310/PAWS/. With that said, I need to have IIS Express use SSL locally. So, when I configure my ASP.NET MVC4 project to use IIS Express. mvc4 project configuration

When I check this in to TFS (source control) and another developer on the team gets latest. The project will not load for them.

MVC4 project wont load

Visual Studio 2012 will display the following error messages when opening the solution: VS2012 error 1 VS2012 error 2

This is because IIS Express wont automatically read the project file and add the HTTPS binding to the site configuration. This is the configuration that VS adds to IIS Express' applicationhost.config file

<site name="PAWS.Web-Site" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\larsene\Documents\My Web Sites\PAWS.Web-Site14" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:44310:localhost" />
    </bindings>
</site>

But I need it to have the binding protocol set to HTTPS like so:

<binding protocol="https" bindingInformation="*:44310:localhost" />

I can either manually enter that into the applicationhost.config. Or I can run the appcmd.exe like so to configure it.

"%ProgramFiles(x86)%\IIS Express\appcmd.exe" set site /site.name:PAWS.Web-Site /bindings:https/*:44310:localhost

But either of these 2 methods is not what I want. I don't want to have to explain to every developer that works on this project to have to manually edit their IIS Express settings before they can even load the project.

How to recreate the problem:

This is easily re-createable by first closing VS2012. Then deleting the config folder for IIS Express located in

%USERPROFILE%\Documents\IISExpress

and then open VS2012 and also open the solution to the MVC4 project that's configured to use IIS Express with https. Now, VS2012 will fail to load the project and complain about no secure bindings.

What am I doing wrong or how can I fix this so that people who get latest on my project will just be able to run it?

9条回答
做自己的国王
2楼-- · 2019-03-12 04:59

You need to set SSL Enabled to True in the project's properties list in order to have that binding show up automatically. (per Scott Hanselman)

As seen in Visual Studio 2010

查看更多
Root(大扎)
3楼-- · 2019-03-12 04:59

Have you tried to manually configure the port in the .csproj file? Once you've configured it there, it should carry over to other workstations:

<IISExpressSSLPort>44310</IISExpressSSLPort>

Also, the project's user file can still cause issues even with the "Apply server settings to all users" option checked. I normally just delete the user file when I fix SSL issues with IIS Express, because it's much easier to just reconfigure my user settings after I've fixed my issue.

查看更多
姐就是有狂的资本
4楼-- · 2019-03-12 05:00

I have recently had a very similar issue and came across this post when trying to resolve. One thing I have noticed is that IIS Express seems to get very distressed if more than one site is set up with a HTTPS binding in the applicationhost.config file.

In my case, I had 2 sites set up to use the same SSL binding to port 44300, changing the port number on one of the SSL bindings on one of the sites caused errors similar to the ones in the OP. I ended up having to remove one of the sites, which is not ideal.

After a little more digging, I tried toggling the 'Require SSL' property from true to false, and back to true. This triggered an update the applicationhost.config which created a new SSL binding with a new port number.

I got into this mess because I had copied an existing project and my config was trying to share ports between 2 sites.

查看更多
爷的心禁止访问
5楼-- · 2019-03-12 05:02

This looks like it might be a bug in VS2012... The only way I've been able to handle this is by hand editing the IISExpress configuration file: applicationhost.config, located under C:\Users\YOUR_USER_NAME\Documents\IISExpress\config. Then under 'sites' I modified the block for the specific application's website:

    <site name="YourSite" id="1">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="c:\..." />
            </application>
            <bindings>
                <binding protocol="https" bindingInformation="*:YOUR_PORT_#:localhost" />
            </bindings>
    </site>

Change the 'binding protocol' to 'https' and make sure you start Visual Studio 2012 with Admin privileges, at least until the site is created/modified in IIS Express.

Hope this helps...

查看更多
何必那么认真
6楼-- · 2019-03-12 05:06

Have you tried opening the project as an admin (run VS2012 as an administrator)?

Usually when you get the above errors (configuring web xxx for ASP.NET 4.5 failed...) and (creation of the virtual directory xxx failed) is because visual studio does not have enough privileges.

May not be your problem, but it doesn't hurt to try.

查看更多
唯我独甜
7楼-- · 2019-03-12 05:10

I have recently come across this same problem, and I've been able to determine why it's happening.

Visual Studio is using the Project Url setting to set the IIS Express http binding, and then it looks at the IISExpressSSLPort setting to set the https binding.

However, if you've changed the Project Url to an https address, that is when Visual Studio gets confused. For the purposes of IIS Express binding updating, it assumes that you've entered an http address for the Project Url and doesn't seem to be able to handle an https address being there.

This complicates things since changing the Project Url to an https address is the only way I've found to make Visual Studio start debugging the https url by default.

So, this seems to be a problem in how Visual Studio is handling the IIS Express binding updates. I'm not aware of a good workaround that allows both the automated binding updates and to start debugging with the https address loaded.

查看更多
登录 后发表回答