Skip to main content


Showing posts from September, 2018

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