Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace AspNetCore.RouteAnalyzer.SampleWebProject.Controllers
{
Expand Down
9 changes: 1 addition & 8 deletions AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace AspNetCore.RouteAnalyzer.SampleWebProject
{
Expand Down
21 changes: 9 additions & 12 deletions AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Diagnostics;

namespace AspNetCore.RouteAnalyzer.SampleWebProject
Expand All @@ -30,13 +27,15 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IApplicationLifetime applicationLifetime,
IWebHostEnvironment env,
IHostApplicationLifetime applicationLifetime,
IRouteAnalyzer routeAnalyzer
)
{
m_routeAnalyzer = routeAnalyzer;

app.UseRouting();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand All @@ -49,12 +48,10 @@ IRouteAnalyzer routeAnalyzer

app.UseStaticFiles();

app.UseMvc(routes =>
app.UseEndpoints(config =>
{
routes.MapRouteAnalyzer("/routes");
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
config.MapControllers();
config.MapRouteAnalyzer();
});

// Lifetime events
Expand All @@ -67,7 +64,7 @@ void OnStarted()
{
var infos = m_routeAnalyzer.GetAllRouteInformations();
Debug.WriteLine("======== ALL ROUTE INFORMATION ========");
foreach(var info in infos)
foreach (var info in infos)
{
Debug.WriteLine(info.ToString());
}
Expand Down
9 changes: 5 additions & 4 deletions AspNetCore.RouteAnalyzer/AspNetCore.RouteAnalyzer.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Version>0.5.3</Version>
<AssemblyVersion>0.5.3.0</AssemblyVersion>
<FileVersion>0.5.3.0</FileVersion>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;

namespace AspNetCore.RouteAnalyzer.Controllers
{
Expand Down
9 changes: 9 additions & 0 deletions AspNetCore.RouteAnalyzer/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AspNetCore.RouteAnalyzer.Inner;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -23,5 +24,13 @@ public static IRouteBuilder MapRouteAnalyzer(this IRouteBuilder routes, string r
routes.Routes.Add(new Router(routes.DefaultHandler, routeAnalyzerUrlPath));
return routes;
}

public static IEndpointRouteBuilder MapRouteAnalyzer(this IEndpointRouteBuilder routes, string routeAnalyzerUrlPath = null)
{
RouteAnalyzerUrlPath = routeAnalyzerUrlPath ?? "/routes";
routes.MapControllerRoute("routeAnalyzer", "{controller=RouteAnalyzer_Main}/{action=ShowAllRoutes}");
routes.MapGet(RouteAnalyzerUrlPath, async context => context.Response.Redirect("RouteAnalyzer_Main/ShowAllRoutes"));
return routes;
}
}
}
4 changes: 1 addition & 3 deletions AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;

namespace AspNetCore.RouteAnalyzer
{
Expand Down
8 changes: 4 additions & 4 deletions AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -58,14 +58,14 @@ public IEnumerable<RouteInformation> GetAllRouteInformations()
}
info.Invocation = $"{e.ControllerName}Controller.{e.ActionName}";
}

// Extract HTTP Verb
if (_e.ActionConstraints != null && _e.ActionConstraints.Select(t => t.GetType()).Contains(typeof(HttpMethodActionConstraint)))
{
HttpMethodActionConstraint httpMethodAction =
HttpMethodActionConstraint httpMethodAction =
_e.ActionConstraints.FirstOrDefault(a => a.GetType() == typeof(HttpMethodActionConstraint)) as HttpMethodActionConstraint;

if(httpMethodAction != null)
if (httpMethodAction != null)
{
info.HttpMethod = string.Join(",", httpMethodAction.HttpMethods);
}
Expand Down
3 changes: 0 additions & 3 deletions AspNetCore.RouteAnalyzer/Inner/Router.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCore.RouteAnalyzer.Inner
Expand Down
27 changes: 27 additions & 0 deletions AspNetCore.RouteAnalyzer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60933/",
"sslPort": 44377
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AspNetCore.RouteAnalyzer": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}