diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj b/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj index e3bd8af..3eae054 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj @@ -1,10 +1,10 @@ - + - netcoreapp2.0 + netcoreapp3.0 - - + + diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs index def3243..20019b1 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs @@ -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 { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs index a5892af..261c7cd 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs @@ -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 { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs index 260d9e4..ade0676 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs @@ -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 @@ -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(); @@ -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 @@ -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()); } diff --git a/AspNetCore.RouteAnalyzer/AspNetCore.RouteAnalyzer.csproj b/AspNetCore.RouteAnalyzer/AspNetCore.RouteAnalyzer.csproj index 84028df..a445482 100644 --- a/AspNetCore.RouteAnalyzer/AspNetCore.RouteAnalyzer.csproj +++ b/AspNetCore.RouteAnalyzer/AspNetCore.RouteAnalyzer.csproj @@ -1,15 +1,16 @@ - + - netcoreapp2.0 + netcoreapp3.0 0.5.3 0.5.3.0 0.5.3.0 + + Library + - - diff --git a/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs b/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs index 4185f10..7a72047 100644 --- a/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs +++ b/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs @@ -1,7 +1,4 @@ using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Text; namespace AspNetCore.RouteAnalyzer.Controllers { diff --git a/AspNetCore.RouteAnalyzer/Extensions.cs b/AspNetCore.RouteAnalyzer/Extensions.cs index f5eeca1..23d13c9 100644 --- a/AspNetCore.RouteAnalyzer/Extensions.cs +++ b/AspNetCore.RouteAnalyzer/Extensions.cs @@ -1,4 +1,5 @@ using AspNetCore.RouteAnalyzer.Inner; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -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; + } } } diff --git a/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs b/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs index 7480980..97b6ac8 100644 --- a/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs +++ b/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace AspNetCore.RouteAnalyzer { diff --git a/AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs b/AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs index 68ba69d..cc55af1 100644 --- a/AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs +++ b/AspNetCore.RouteAnalyzer/Inner/RouteAnalyzerImpl.cs @@ -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; @@ -58,14 +58,14 @@ public IEnumerable 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); } diff --git a/AspNetCore.RouteAnalyzer/Inner/Router.cs b/AspNetCore.RouteAnalyzer/Inner/Router.cs index 8433d70..5dc949e 100644 --- a/AspNetCore.RouteAnalyzer/Inner/Router.cs +++ b/AspNetCore.RouteAnalyzer/Inner/Router.cs @@ -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 diff --git a/AspNetCore.RouteAnalyzer/Properties/launchSettings.json b/AspNetCore.RouteAnalyzer/Properties/launchSettings.json new file mode 100644 index 0000000..8c9f0a6 --- /dev/null +++ b/AspNetCore.RouteAnalyzer/Properties/launchSettings.json @@ -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" + } + } +} \ No newline at end of file