Skip to content

Instantly share code, notes, and snippets.

View rynowak's full-sized avatar
🤪

Ryan Nowak rynowak

🤪
View GitHub Profile
@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
@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;

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:

$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
// 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;
// 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;