https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6587 - Clean up and fixed issue with Ambiguous actions
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
public class DetermineAmbiguousActionByPassingParameters : ActionMethodSelectorAttribute
|
||||
{
|
||||
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
|
||||
{
|
||||
var parameters = action.Parameters;
|
||||
if (parameters.Any())
|
||||
{
|
||||
var canUse = true;
|
||||
foreach (var parameterDescriptor in parameters)
|
||||
{
|
||||
var value = routeContext.HttpContext.Request.Query[parameterDescriptor.Name];
|
||||
|
||||
if (parameterDescriptor.ParameterType == typeof(Udi))
|
||||
{
|
||||
canUse &= UdiParser.TryParse(value, out _);
|
||||
}
|
||||
else if (parameterDescriptor.ParameterType == typeof(int))
|
||||
{
|
||||
canUse &= int.TryParse(value, out _);
|
||||
}
|
||||
else if (parameterDescriptor.ParameterType == typeof(Guid))
|
||||
{
|
||||
canUse &= Guid.TryParse(value, out _);
|
||||
}
|
||||
else if (parameterDescriptor.ParameterType == typeof(string))
|
||||
{
|
||||
canUse = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canUse = false;
|
||||
}
|
||||
}
|
||||
|
||||
return canUse;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user