Generate a self-signed certificate for IIS with a custom common name

Using the IIS Manager you can generate self-signed certificates for HTTPS bindings. The certificates generated by the IIS Manager have the limitation that the common name (CN) of the certificate is always the computer name.

If you wish to set an own common name for the certificate, you can use following command in PowerShell (open as administrator) to generate a new self-signed certificate.

New-SelfSignedCertificate -DnsName "my.customdomain.com" -FriendlyName "MyServiceName" -NotAfter (Get-Date).AddYears(10)

Challenge authentication using a custom middleware.

Sometimes you write an ASP.NET Core application without using MVC. For example an microservice or an application serving static files.

Anyhow you might want to secure your application using authentication. I was facing the problem, how I could challenge authentication when I’m not using MVC.

The solution is writing a custom middleware that challenges authentication.

Modify the window URL without reloading the page

Today I found an easy┬ásolution for the problem that if you’re changing the URL of the current window with JavaScript in the traditonal way, unfortenately the whole page will be reloaded.

window.location = "http://peter-doering.com/mynewurl"

You may want to update the URL after you’ve updated parts of the page with an Ajax call. This would enable the users to share the current page as link or to add an bookmark.

HTML5 introduced a new API for manipulating the browsers history. You can use the pushState()-method to change the current page url without page reload.

history.pushState(null, null, "http://peter-doering.com/mynewurl")
history.pushState(null, null, "http://peter-doering.com?id=1234")