Programming Tutorials

AmbiguousMatchException: The request matched multiple endpoints.

By: Manoj in Asp.net Tutorials on 2023-06-01  

The AmbiguousMatchException you encountered means that there are multiple endpoints in your code that match the incoming request. This can happen when you have multiple actions in a controller with the same name and same HTTP verb.

To resolve this issue, you need to make sure that each endpoint has a unique name or route. Here are a few possible solutions:

  1. Rename the conflicting action methods: Give each action method in your controller a unique name that reflects its purpose. For example, instead of having two Index methods, you can rename them to Index1 and Index2.

  2. Use attribute routing: Decorate your action methods with specific route attributes to differentiate them. By using [Route] attribute, you can specify unique routes for each action method. For example:

    [Route("api/controller/action1")]
    public IActionResult Action1()
    {
        // Action1 implementation
    }
    
    [Route("api/controller/action2")]
    public IActionResult Action2()
    {
        // Action2 implementation
    }
    
  3. Use HTTP verbs to differentiate: If the actions have the same name but serve different HTTP verbs, you can use the [HttpGet], [HttpPost], [HttpPut], etc. attributes to specify the appropriate HTTP verb for each action. For example:
    [HttpGet]
    public IActionResult Index()
    {
        // GET Index implementation
    }
    
    [HttpPost]
    public IActionResult Index()
    {
        // POST Index implementation
    }
    

By making these changes, you ensure that each endpoint has a unique identifier, and the AmbiguousMatchException should be resolved.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Asp.net )

Visual Basic .NET Vs Visual C# - (Differences)

One client credential type required either: ClientSecret, Certificate, ClientAssertion or AppTokenProvider must be defined when creating a Confidential Client. Only specify one

IIS and WAP. Configuring IIS to deliver WML (WAP content)

Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

AmbiguousMatchException: The request matched multiple endpoints.

Downloading and Installing the AWS SDK for .NET

DataGrid Control in ASP.net

ActiveX component can't create object: 'CDONTS.NewMail' - ASP

Getting started with ASP

What is ASP.NET?

Advantages of ASP.NET

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Passing a model globally to all Views in your Asp.net webapp

Latest Articles (in Asp.net)

Things to note when changing a function to async in your controller

AmbiguousMatchException: The request matched multiple endpoints.

Call an Action in a controller when user clicks a button in View

Button that is only clickable when the checkbox is checked

Pass the same model to multiple views within the same controller

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Severity Code Description Project File Line Suppression State Error CS0103 The name 'JsonConvert' does not exist in the current context.

Passing a model globally to all Views in your Asp.net webapp

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

One client credential type required either: ClientSecret, Certificate, ClientAssertion or AppTokenProvider must be defined when creating a Confidential Client. Only specify one

Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of the same dependent assembly.

Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)

Pagination in ASP.net core application

Microsoft.Identity vs Microsoft.IdentityModel.Clients.ActiveDirectory

Related Tutorials

Things to note when changing a function to async in your controller

AmbiguousMatchException: The request matched multiple endpoints.

Call an Action in a controller when user clicks a button in View

Button that is only clickable when the checkbox is checked

Pass the same model to multiple views within the same controller

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Severity Code Description Project File Line Suppression State Error CS0103 The name 'JsonConvert' does not exist in the current context.

Passing a model globally to all Views in your Asp.net webapp

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

One client credential type required either: ClientSecret, Certificate, ClientAssertion or AppTokenProvider must be defined when creating a Confidential Client. Only specify one

Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of the same dependent assembly.

Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)

Pagination in ASP.net core application

Microsoft.Identity vs Microsoft.IdentityModel.Clients.ActiveDirectory