Click here to Skip to main content
15,886,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, when I am trying to access one of the views in my ASP .NET MVC app I am getting following error:
AmbiguousMatchException: The request matched multiple endpoints. Matches:

RockWorld.Web.Controllers.Admin.PageParametersController.Index (RockWorld.Web)
RockWorld.Web.Controllers.Admin.PageParametersController.OperationProgress (RockWorld.Web).

It is the only controller on my app on which I am getting this error.

My controller:
C#
    [Authorize(Roles = UserGroups.CmsAdmins)]
	[Route("/Admin/[controller]")]
	public class PageParametersController : Controller
	{
        private readonly IPageParametersService _pageParametersService;
        private readonly IApplicationOptions _applicationOptions;
        private readonly ILogger<PageParametersController> _logger;
        private readonly IPageParametersProgressService _progressService;
        private readonly IRequiredClientResourceList _requiredClientResourceList;

        public PageParametersController(
            IPageParametersService pageParametersService,
            IApplicationOptions applicationOptions,
            ILogger<PageParametersController> logger,
            IPageParametersProgressService pageParametersProgressService,
            IRequiredClientResourceList requiredClientResourceList)
        {
            _pageParametersService = pageParametersService;
            _applicationOptions = applicationOptions;
            _logger = logger;
            _progressService = pageParametersProgressService;
            _requiredClientResourceList = requiredClientResourceList;
        }

        public ActionResult Index()
        {
            if (!_applicationOptions.IsUpdatePageParameters)
            {
                return null;
            }

            _requiredClientResourceList.RequireStyleInline($"{AdminLayoutCssClasses.MT6} {AdminLayoutCssClasses.InfoTextArea} {AdminLayoutCssClasses.EpiButtonDefault}").AtHeader();

            return View("/Views/Admin/PageParameters/Index.cshtml");
        }

        [HttpPost]
        public ActionResult Update(IFormFile file)
        {
            if (_progressService.IsRunning)
            {
                return OperationProgress();
            }

            if (!_applicationOptions.IsUpdatePageParameters)
            {
                return null;
            }

            if (file == null)
            {
                _progressService.AddErrorLog("File not found");

                return new JsonResult(new PageParametersResult { IsRunning = false });
            }

            string fileExtension = Path.GetExtension(file.FileName);

            if (fileExtension != ".csv")
            {
	            _progressService.AddErrorLog("Invalid file format");

	            return new JsonResult(new PageParametersResult { IsRunning = false });
            }

            List<PageParameters> pageParametersList = _pageParametersService.ConvertCsvContentToList(file);

            if (pageParametersList == null || !pageParametersList.Any())
            {
	            return new JsonResult(new PageParametersResult { IsRunning = false });
            }

            pageParametersList.RemoveAll(x => x == null);

            CheckDuplicates(pageParametersList);

            Task task = null;
            task = Task.Run(() =>
            {
	            try
	            {
		            _progressService.SetApplicationStatus(true, task);

		            _pageParametersService.UpdatePageParameters(pageParametersList);
	            }
	            catch (Exception ex)
	            {
		            _logger.LogError(ex.Message);
		            _progressService.AddInfoLog("Update parameters failed");
	            }
	            finally
	            {
		            _progressService.SetApplicationStatus(false, task);
	            }
            });

            return new JsonResult(new PageParametersResult { IsRunning = true });
        }

        public ActionResult OperationProgress()
        {
            string logs = _progressService.GetLogs();

            return new JsonResult(new PageParametersResult { IsRunning = _progressService.IsRunning, Logs = logs });
        }

        private void CheckDuplicates(List<PageParameters> pageParametersList)
        {
            var duplicatedIds = pageParametersList.GroupBy(x => x.EPIPageId).Where(x => x.Count() > 1).Select(x => x.Key)
                .ToList();

            if (duplicatedIds.Any())
            {
                foreach (var id in duplicatedIds)
                {
                    _progressService.AddErrorLog($"Duplicated value for page with id: {id}");

                    pageParametersList.RemoveAll(x => x.EPIPageId == id);
                }
            }
        }
    }
}


My view:
C#
@using EPiServer.Framework.Web
@using EPiServer.Framework.Web.Mvc.Html
@using RockWorld.Web
@using EPiServer.Framework.Web.Resources
@{
Layout = "~/Views/Layouts/ToolsLayout.cshtml";
ViewBag.SectionTitle = "Page parameters";
}
<div class="mt-6 ms-2">
      <h2>@ViewBag.SectionTitle</h2>
      <div class="epi-contentContainer epi-padding">
         <div class="epi-contentArea">
            <h1 class="EP-prefix">
               Update page parameters
            </h1>
            <p class="EP-systemInfo">This tool will go through all pages and update ones which are specified in excel file.</p>
            <div id="FullRegion_ValidationSummary" class="EP-validationSummary" style="color: Black; display: none;"></div>
         </div>
         <div class="epi-contentArea epi-formArea">
            <fieldset class="border rounded-3 p-3">
               <legend class="float-none w-auto px-3">Choose csv file.</legend>
               <label>Excel File</label>
               <input id="parametersFile" type="file" name="file" accept=".csv" />
            </fieldset>
            <p class="mt-2">Only pages specified in file will be updated.</p>
            <div class="epi-buttonDefault">
               
               <input class="epi-cmsButton-text epi-cmsButton-tools epi-cmsButton-Refresh" type="submit" name="btnSubmit" id="updateParametrsSubmit" value="Submit" />
               
            </div>
         </div>
         <div>
            <h3>Result:</h3>
            <textarea id="InfoTextArea" disabled rows="10" cols="50"></textarea>
         </div>
      </div>
   </div>
   @Html.RequiredClientResources(RenderingTags.Header)
   @Url.RenderScripts(BundleNames.DependenciesBundle, BundleNames.PageParametersUpdate)


What I have tried:

I tried to rectify this issue by adding route constraints to the methods, but this didn't fix my issue.
Posted
Updated 22-Jul-22 0:13am

1 solution

A GET request to /Admin/PageParameters/ matches both your Index and OperationProgress actions.

You need to change either the method or the route for the OperationProgress action.

For example, if you add:
C#
[HttpGet("[action]")
public ActionResult OperationProgress()
then GET /Admin/PageParameters/ will map to Index, and GET /Admin/PageParameters/OperationProgress will map to OperationProgress.
 
Share this answer
 
Comments
Member 15341738 22-Jul-22 8:03am    
Yes, that worked. Thanks!
Maciej Los 22-Jul-22 9:02am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900