Skip to main content

Posts

A non-useful Powershell snippet

What can I say, I was distracted

$t = "Taste the rainbow "; $c = ([ConsoleColor].GetEnumNames()); (1..7) | % {$c += $c; $t += $t}; foreach($x in $c) { write-host $t -ForegroundColor $x -NoNewline; sleep -Milliseconds 50 }
Recent posts

Strongly-typed action links in ASP.NET Core MVC views

While experimenting with ASP.NET Core and Razor views it occurred to me that the magic-string-based links really weren't ideal, so I did a little googling and came across the excellent AspNet.Mvc.TypedRouting nuget package, which lets you use strongly-typed references to controllers and action methods.

I won't repeat the install instructions, but for some reason they didn't provide any examples of using their extension methods with the one thing I wanted to do - action links.  For future reference, here's an example of how to use them in a Razor view

<li>@( Html.ActionLink<AppController>("Home", c => c.Index()) )</li>
<li>@( Html.ActionLink<AppController>("Test", c => c.Test()) )</li>



Adding Application Insights to a .NET Core application

$appInsights = New-AzureRmApplicationInsights -Location USEast -ResourceGroupName rgname -Name ainame
$appInsights.InstrumentationKey #copy this

dotnet new mvc
dotnet add package Microsoft.ApplicationInsights.AspNetCore

In appsettings.json, add this
{
  "ApplicationInsights": {
    "InstrumentationKey": "11111111-2222-3333-4444-555555555555"
  }
}

In program.cs add UseApplicationInsights() to the method chain for CreateDefaultBuilder

dotnet run

Ref: https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-with-Application-Insights-for-ASP.NET-Core

IIS secured local debugging

Download and run this:
https://github.com/mwanchap/configs/blob/master/SetupLocalhostCerts.ps1

For each project:

Open Visual StudioIn Solution Explorer, select the web project and press F4 to open properties (not right click -> Properties, that's a different set of properties for some reason)Set "SSL Enabled" = TrueCopy the SSL URLRight click on the project name in Solution Explorer again and open Properties from thereSelect "Web" sectionPaste SSL URL into "Project Url" TODO: script to enable edit-and-continue for local IIS
Credit: PS script derived from a similar one by camieleggermont at https://gist.github.com/camieleggermont/5b2971a96e80a658863106b21c479988 Enabling Edit-and-Continue for Local IIS from https://stackoverflow.com/a/50509545/2939759

Visual Studio: Edit and Continue issues

Huge thanks to Steve French for this one

Like him, I'd been having issues with "Edit and Continue" not working for ages.  I tried everything and none of the usual advice helped at all.  Finally I came across Steve's post here, and as he suggests, uninstalling Stackify Prefix immediately fixed the problem. Turns out everything was fine to start with, it was just Prefix that was getting in the way (probably due to the way it injects itself into the runtime / server / etc).

For reference other settings I tried included:
Tools -> Options -> Debugging -> Enable Edit and Continue
Project Properties -> Web -> Enable Edit and Continue

It kind of sucks because I really liked Prefix, but it's only useful in specific situations, whereas Edit and Continue is much more useful. I guess I'll have to find another profiler...

Installing SQL Server Express to set up an Azure database locally

Installing SQL Express:Download SQL Express installerSwitch to an account with full local admin permissions (our regular accounts don't have these so I had to use a global admin account instead) and install SQL Express with that accountOnce installation completes, make a note of the connection string you're given on the final page of the installerOpen SSMS and connect to the database - default name is localhost\sqlexpressNavigate to Security -> Logins -> New LoginAdd the regular (non-admin) domain account that you'll be using most of the timeOnce added, open that account under the Logins section and then open the "Server Roles" pageAdd the account to the "sysadmin" role Obtaining the Azure database:Open the database and select the "Export" option at the top of the "Overview" pageChoose a storage account and container to drop the export file in and enter the server admin credsOnce the file has been created, access that storage …

Dynamics CRM Microsoft.IdentityModel exception in Windows 10

When trying to connect to Dynamics CRM services on a Windows 10, machine, you might get this error:

Could not load file or assembly ‘Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies

There are plenty of blog posts around that will all tell you to go and install "Windows Identity Foundation", however this is no longer the case for Windows 10 and the installer for WIF will fail.  This is because it's now a Windows feature - install it via the "Turn Windows features on or off" section in "Programs and Features" as mentioned here.