Categories
PowerShell

Repeat a command in PowerShell

I just learned something cool new in PowerShell: that you can generate ranges with the “..” operator.

This works even in the old Windows PowerShell.

This is especially cool when you want to repeat a command a certain number of times in a loop.

Categories
Allgemein

Use ng serve with Angular 8 and Internet Explorer

Angular 8 introduced the new ECMAScript standard ES2015. ES2015 is more efficient. Older browsers like IE 11 does support only the previously used ES5. To still have support for IE 9-11 Angular has new feature called Differential Loading. In short it is serving the Angular App in two versions: a ES5 version and ES2015 version. So each browser can decide which version to use.

Unfortunately if your using the Angular Develpment Server ng serve, it will use only ES2015. The reason is, that it would be too slow to compile it always twice for ES2015 and ES5.

There’s a trick how to run ng serve with ES5.

In the file browserslist remove the “not” before “IE 9-11”.

> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11

Beside your tsconfig.json add a file tsconfig-es5.json with content:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "target": "es5"
    }
}

Add a new configuration “es5” in the “configurations” and “serve” sections of your angular.json:

{
  ...
  "projects": {
    "my-app": {
      ...
      "configurations": {
        ...
        "es5": {
          "tsConfig": "./tsconfig-es5.json"
        }
      }
    },
    "serve": {
      ...
      "configurations": {
        "production": {
          "browserTarget": "my-app:build:production"
        },
        "es5": {
          "browserTarget": "my-app:build:es5"
        }
      }
    }
    ...
  }
}

Optionally you can add a script to package.json:

"scripts": {
  "start": "ng serve",
  "ie": "ng serve -c es5",
}

Now you can run your Angular App with IE support using:

npm run ie
Categories
.NET C#

async/await: Why don’t use Task.Wait()?

In short explained why you should never use Task.Wait() to wait for an asynchronous task to complete from a synchronous context.

The Wait() method always returns an AggregateException if an error occurs within the task execution.

It would be hard to handle the real exception which is wrapped within the AggregateException.

Use GetAwaiter().GetResult() instead. It will return the real exception.

Categories
PowerShell Web

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)
Categories
PowerShell

Generate a GUID

Here’s a small but very useful PowerShell script to generate GUIDs in different formats.

Categories
PowerShell

Monitor text files with PowerShell

You can use this method with PowerShell as alternative to the tail command at Linux.

Categories
PowerShell

Visualize data in PowerShell as GridView.

When using PowerShell, did you ever wish to have a function to pipe structured data to visualize it.

PowerShell has a great built-in function for that: Out-GridView.
You can even filter the rows in the grid.

Categories
Web

Calculate width with CSS

CSS 3 has a new method calc(), which gives you possibility to align elements. You can mix proportions and fixed measures.

width: calc(100% – 40px);
Categories
.NET C#

Built-in .NET-function to generate passwords

Recently I’ve found a method GeneratePassword() in the good old .NET full framework, in the System.Web.Security-namespace. It has two parameters to specify the complexity of the password.

public static string GeneratePassword (int length, int numberOfNonAlphanumericCharacters);

Categories
.NET Allgemein ASP.NET C# Web

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.