Using "UseMvc" to configure MVC is not supported while using Endpoint Routing

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for Using "UseMvc" to configure MVC is not supported while using Endpoint Routing

🚀 Solving the "Using 'UseMvc' with Endpoint Routing" Issue in .NET Core 3.0

If you're working with an ASP.NET Core 2.2 project and recently upgraded to .NET Core 3.0 Preview 8, you might have come across a warning message that says:

"Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'."

👉 The Problem: You're now wondering what this warning means and how to solve it properly. Well, worry not. In this blog post, we'll explore the issue and discuss why Endpoint Routing doesn't need the traditional UseMvc() function. Plus, we'll provide you with the proper solution to overcome this problem. Let's dive in! 💪

The warning is triggered because ASP.NET Core 3.0 introduced a new routing system called Endpoint Routing, which provides a more integrated and flexible way to handle routing within the application. With Endpoint Routing, developers no longer need to use the UseMvc() function, as it is not required.

✅ The Solution: Instead of using UseMvc(), you can simply use the UseEndpoints() method to configure your endpoints. Here's the proper way to solve this issue:

public void ConfigureServices(IServiceCollection services)
{
    // Other service configurations

    services.AddControllers(); // Add this line

    services.Configure<MvcOptions>(options => 
    {
        options.EnableEndpointRouting = false; // Set Endpoint Routing to false
    });
}

public void Configure(IApplicationBuilder app)
{
    // Other app configurations

    app.UseRouting(); // Add this line

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers(); // Add this line
    });
}

By adding services.AddControllers() in the ConfigureServices method and configuring MvcOptions to disable Endpoint Routing, you ensure that your MVC configuration is properly handled without using UseMvc().

💡 Why Does Endpoint Routing Not Need UseMvc()? Endpoint Routing takes advantage of the new middleware pipeline introduced in ASP.NET Core 3.0. It integrates routing functionality directly into the pipeline, eliminating the need for additional configuration using UseMvc().

With Endpoint Routing, you can define routes directly on your controllers and actions using attributes like [Route]. This simplifies the configuration process and makes your code cleaner and more maintainable.

📣 Your Turn: Now that you know how to solve the "Using 'UseMvc' with Endpoint Routing" issue, go ahead and implement the solution in your project. If you have any questions or insights, feel free to share them in the comments below. Happy coding! 😊👩‍💻


Don't miss out on more exciting tech tips and guides! Subscribe to our newsletter for regular updates and follow us on Twitter for daily tech goodness. 💌🐦

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my