Skip to content

Commit

Permalink
Fix defaultAction url
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Mar 25, 2020
1 parent d72a191 commit 4a4db10
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 65 deletions.
14 changes: 14 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
daysUntilLock: 90

skipCreatedBefore: false

exemptLabels: []

lockLabel: false

lockComment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related problems.
setLockReason: true
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.0.100
dotnet-version: 3.1.200
- name: Build DNTCaptcha.Core lib
run: dotnet build ./src/DNTBreadCrumb.Core/DNTBreadCrumb.Core.csproj --configuration Release
19 changes: 0 additions & 19 deletions .github/workflows/nuget.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/DNTBreadCrumb.Core.TestWebApp/bin/Debug/netcoreapp2.2/DNTBreadCrumb.Core.TestWebApp.dll",
"program": "${workspaceRoot}/src/DNTBreadCrumb.Core.TestWebApp/bin/Debug/netcoreapp3.1/DNTBreadCrumb.Core.TestWebApp.dll",
"args": [],
"cwd": "${workspaceRoot}/src/DNTBreadCrumb.Core.TestWebApp",
"stopAtEntry": false,
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "3.1.200"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
Expand All @@ -15,7 +15,7 @@
<Exec Command="dotnet bundle" />
</Target>
<ItemGroup>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.9.406" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="3.2.435" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DNTBreadCrumb.Core\DNTBreadCrumb.Core.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DNTBreadCrumb.Core\DNTBreadCrumb.Core.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;

namespace DNTBreadCrumb.Core.TestWebApp.Controllers
{
[BreadCrumb(Title = "Pool Manager", Order = 0, UseDefaultRouteUrl = true)]
public class ManagePoolController : Controller
{
[BreadCrumb(Title = "List of pool", Order = 1)]
public IActionResult NotIndex() // it's a default action here
{
return View();
}

[BreadCrumb(Title = "Create a pool", Order = 1)]
public IActionResult Create()
{
return View();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>DNTBreadCrumb.Core.TestWebApp</AssemblyName>
<OutputType>Exe</OutputType>
Expand All @@ -14,10 +14,10 @@
<ItemGroup>
<ProjectReference Include="..\DNTBreadCrumb.Core\DNTBreadCrumb.Core.csproj" />
</ItemGroup>
<Target Name="PrecompileScript" BeforeTargets="BeforeBuild">
<!--<Target Name="PrecompileScript" BeforeTargets="BeforeBuild">
<Exec Command="dotnet bundle" />
</Target>
</Target>-->
<ItemGroup>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.9.406" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="3.2.435" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions src/DNTBreadCrumb.Core.TestWebApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Account}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "notDefault",
pattern: "Test/{controller=ManagePool}/{action=NotIndex}/{id?}",
constraints: new { controller = "^ManagePool$" }
);
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>

Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@
<a asp-area="" asp-controller="DisplayName" asp-action="Reports">Reports</a>
</li>
</ul>
<ul class="list-group">
<li class="list-group-item">
<a asp-area="" asp-controller="ManagePool" asp-action="NotIndex">ManagePool/Index</a>
</li>
<li class="list-group-item">
<a asp-area="" asp-controller="ManagePool" asp-action="Create">ManagePool/Create</a>
</li>
</ul>
</div>
38 changes: 7 additions & 31 deletions src/DNTBreadCrumb.Core/BreadCrumbAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Routing;

namespace DNTBreadCrumb.Core
{
Expand Down Expand Up @@ -122,15 +120,15 @@ private static bool isAjaxRequest(ActionExecutingContext filterContext)

private string getDefaultControllerActionUrl(ActionExecutingContext filterContext)
{
var defaultAction = getDefaultAction(filterContext);
var defaultAction = string.Empty;
var urlHelper = getUrlHelper(filterContext);

if (RemoveAllDefaultRouteValues)
{
return urlHelper.ActionWithoutRouteValues(defaultAction);
}

if (RemoveRouteValues == null || !RemoveRouteValues.Any())
if (RemoveRouteValues?.Any() != true)
{
return urlHelper.Action(defaultAction);
}
Expand All @@ -140,8 +138,7 @@ private string getDefaultControllerActionUrl(ActionExecutingContext filterContex

private static IUrlHelper getUrlHelper(ActionExecutingContext filterContext)
{
var controller = filterContext.Controller as Controller;
if (controller == null)
if (!(filterContext.Controller is Controller controller))
{
throw new NullReferenceException("Failed to find the current Controller.");
}
Expand All @@ -155,43 +152,22 @@ private static IUrlHelper getUrlHelper(ActionExecutingContext filterContext)
return urlHelper;
}

private static string getDefaultAction(ActionExecutingContext filterContext)
{
object defaultActionData;
var defaultRoute = filterContext.RouteData.Routers.OfType<Route>().FirstOrDefault();
if (defaultRoute != null)
{
if (defaultRoute.Defaults.TryGetValue("action", out defaultActionData))
{
return defaultActionData as string;
}
throw new InvalidOperationException("The default action of this controller not found.");
}

if (filterContext.RouteData.Values.TryGetValue("action", out defaultActionData))
{
return defaultActionData as string;
}
throw new InvalidOperationException("The default action of this controller not found.");
}

private void setEmptyTitleFromAttributes(ActionExecutingContext filterContext)
{
if (!string.IsNullOrWhiteSpace(Title))
{
return;
}

var descriptor = filterContext.ActionDescriptor as ControllerActionDescriptor;
if (descriptor == null)
if (!(filterContext.ActionDescriptor is ControllerActionDescriptor descriptor))
{
return;
}

var currentFilter = filterContext.ActionDescriptor
.FilterDescriptors
.Select(filterDescriptor => filterDescriptor)
.FirstOrDefault(filterDescriptor => ReferenceEquals(filterDescriptor.Filter, this));
.FilterDescriptors
.Select(filterDescriptor => filterDescriptor)
.FirstOrDefault(filterDescriptor => ReferenceEquals(filterDescriptor.Filter, this));
if (currentFilter == null)
{
return;
Expand Down
8 changes: 4 additions & 4 deletions src/DNTBreadCrumb.Core/DNTBreadCrumb.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>DNTBreadCrumb.Core Creates custom bread crumb definitions, based on Twitter Bootstrap 3.x and 4.x features.</Description>
<VersionPrefix>1.9.1</VersionPrefix>
<VersionPrefix>1.9.2</VersionPrefix>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>netcoreapp3.0;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;netcoreapp3.0;netstandard1.6;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>DNTBreadCrumb.Core</AssemblyName>
<PackageId>DNTBreadCrumb.Core</PackageId>
Expand Down Expand Up @@ -35,10 +35,10 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PlatformTarget>anycpu</PlatformTarget>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' or '$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0' or '$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>NETCOREAPP3_0</DefineConstants>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion tag-it.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
git tag -a 1.9.1 -m "Published 1.9.1 to nuget.org"
git tag -a 1.9.2 -m "Published 1.9.2 to nuget.org"
git push --follow-tags
pause

0 comments on commit 4a4db10

Please sign in to comment.