Kemal Tezer Dilsiz Kemal Tezer Dilsiz - 8 months ago 34
C# Question

How to migrate routes from .NET to ASP.NET Core? (Specific example)

I am working on a migration from .NET and .NET Core and I am having difficulties with the routing configuration in startup.cs.

From the ASP.NET project, we had the following routing code:

protected void Application_Start()

Now, I am trying to find something that would simply replace this functionality. What I have been working on so far is the following:

app.UseMvc(routes =>
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "GHS", action = "RequestForm" });

this works for a single controller and action but I am looking for something that would "RegisterAllAreas".

I have found the following article from Microsoft but was unable to find anything that specifically matched this.

Is there a way to map all the routes similar to how it was done in .NET code?

Extra information:

I think in the previous version, the url was generated from the View somehow because only the following urls work:




I have just realized that my project has two files named "contact-us.html" and "ghs-request.html" and these html files has the connection to the javascript files. Therefore, I only need to connect my View forms to these html scripts.


Try this

    app.UseMvc(routes =>
        // areas
            name: "area",
            template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

        // default
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");