Developing with .NET 4.5 - nordvall/WifExamples GitHub Wiki

When using .NET 4.5, you don't need any extra assemblies. The claims support is included in the core .NET assemblies.

Run the examples

First download the sample code from this GitHib repository (there is a zip button on the start page). Then follow the instructions in Sample code installation. This is important because the examples below reuse the DummySTS project, and it's certificates are installed with the sample application.

Set up your own project

I recommend a manual approach to set up your procect. See The problem with the Microsoft tools for an explanation.

Preparations

Start with a standard web forms or MVC project in Visual Studio 2012. If you will use HTTPS in production, enable SSL in the project settings in Visual Studio. See Using HTTP vs HTTPS for my thoughts about this. Then follow these steps:

  • Start the web project in debug mode and go to the HTTPS address in a browser.
  • Open the certificate details information in the browser.
  • In the certificate window, go to the Information tab and scroll to the bottom.
  • Copy the contents of the Thumbprint field. Paste it somewhere and remove all the spaces.

You will need the thumbprint later.

Include DummySTS in your project

Copy the DummySTS web application project from the Common folder in the code samples to your solution folder. Include it in your solution (add -> existing project in Visual Studio). Then start your project in debug mode and confirm that you can go to the STS site, on the address https://localhost:44500/.

Insert idetity configuration in your web.config

Find the sample code project here on the site that best matches your setup (HTTP/HTTPS, server/client...) and copy the following parts from its web.config/app.config to your project:

  • configSections
  • system.web/authorization
  • system.webserver/modules
  • system.identityModel
  • system.identityModel.services

Insert identifier

Make up an identifier for your service, it could be something like "urn:yourcompany:yourservice".

  • Edit the the web.config of your own web project and substitute the existing "urn:claimsdemo:xxx" for your own identifier.
  • Add the identifier to the list in web.config of the DummySTS site.

Insert your certificate thumbprint

Take the certificate thumbprint you copied earlier, and substitute the existing thumbprint "a2028f8e7f7b082cd35e81fd0ca0b70b04651abf" in two locations in your web.config.

Also substitute the same thumbprint under EncryptingCertificateHash in the web.config of the DummySTS site.

Test your configuration

Now you should be able to start the website using Debug mode in Visual Studio. Use the "Multiple startup projects" option to start both the DummySTS and your web site at the same time. Go to the web address of your web project in a browser.

Troubleshooting

See Error messages in web browser.

Moving to production

See Moving to production.