Skip to content

Instantly share code, notes, and snippets.

View rynowak's full-sized avatar
🤪

Ryan Nowak rynowak

🤪
View GitHub Profile
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.AspNetCore.Mvc.Internal;
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
$sdk_dir = get-item "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.0.0"
$crossgen_exe = get-item "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.0.0\crossgen.exe"
$pwd = get-item .
foreach ($file in gci . -r -include *.dll)
{
$out =[io.path]::ChangeExtension($file.Name, ".ni.dll")
write-host $crossgen_exe /Platform_Assemblies_Paths """$sdk_dir""" /App_Paths """$pwd"""/out $out $file
& $crossgen_exe /Platform_Assemblies_Paths """$sdk_dir""" /App_Paths """$pwd"""/out $out $file

Routing and MVC

ASP.NET MVC uses the Routing middleware to match the URLs of incoming requests and map them to actions. Routes are defined in startup code or using attributes and describe how URL paths should be matched to actions. MVC also uses the same set of routes to generate URLs to include as links in responses.

This document will explain the interactions between MVC and routing, and how typical MVC applications make sure of routing features. See the for details on how to write more advanced routes.

Setting up Routing Middleware

In your Configure method you may see code like:

@rynowak
rynowak / attribute_routing_2_0.cs
Created January 23, 2017 06:10
The fever dreams of a madman
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Internal;
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.AspNetCore.Routing.Tree;
using Microsoft.Extensions.Logging;
@rynowak
rynowak / TagHelperDescriptor.cs
Created February 14, 2017 21:01
TagHelperDescriptor
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.VisualStudio.LanguageServices.Razor.New
{
public abstract class TagHelperDescriptor

Introduction to Razor Pages

Razor Pages is a new feature to ASP.NET Core MVC that makes coding page-focused scenarios easier and more productive.

Razor Pages is included in version 2.0.0 of ASP.NET Core. Tooling support for Razor Pages in Visual Studio ships in Visual Studio 2017 Update 3.

Getting Started

Razor Pages is on by default by MVC. If you are using a typical Startup.cs like the following, Razor Pages is already enabled.

Issues:

  • Partials used from overridable views need to go into Views/Shared or Pages/Shared in the app. Partials used from the app's layout also need to go into Views/Shared or Pages/Shared in the app. Using other search paths may work well until you start overriding things.

  • @namespace, @using and @addTagHelper are all problematic when it comes to copy-pasting code from a library into an app.

  • build-time errors for razor show up in errors window in VS, but clicking on them doesn't work.

We don't have a gesture to remove/hide a precompiled Razor assembly. Identity will need to disable its precompiled Razor assets by default. Without this feature the precompiled Razor Pages show up when areas are enabled (fails to resolve services) - and do not show up when areas are disabled.

Not Razor Related

@rynowak
rynowak / route_value_invalidation.md
Created June 7, 2018 19:33
Route Value Invalidation

Summary

Routing has a URL generation that feature that tries to make it simple and terse to generate URLs to related endpoints. This involves allowing ambient route values to be used in URL generation to obviate the need to re-specify them. Route value invalidation is the set of rules that govern the cases where routing can and cannot use the ambient values.

Example (Conventional Routing)

public class BlogController : Controller
{
 // Assume we just matched the route "{controller=Home}/{action=Index}/{id?}
# Go paste this into http://viz-js.com/
digraph DFA {
0 -> 1 [label="/emojis"]
0 -> 4 [label="/events"]
0 -> 7 [label="/feeds"]
0 -> 10 [label="/gists"]
0 -> 80 [label="/issues"]
0 -> 83 [label="/markdown"]
0 -> 89 [label="/meta"]