Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Asp.Net Core MVC Routing like Express?

I've used Express (web development framework for node.js) routers and like the routing style. Below an example of some routes.

apiRouter.get("/project/:id",auth.verifyEditor,routes.getProject);
apiRouter.put("/project",auth.verifyEditor,routes.updateProject);
apiRouter.delete("/project/:id",auth.verifyEditor,routes.deleteProject);
apiRouter.get("/project/:id/page/:pageId", auth.verifyEditor,auth.verifyEditor, routes.getPage);
apiRouter.get("/project/:id/page",auth.verifyEditor,routes.getPages);
apiRouter.put("/project/:id/page",auth.verifyEditor,routes.updatePage);

It defines routes with verb (like .get( ... )), route (/project)and route-params (:id), middleware (auth.verifyEditor) and the handler (routes.updatePage) What I like most of this style is

  • The routes are defined centralized
  • The precedence of routes is clear: reading from above the first match is used
  • The mapping to handlers is unambiguous and above all: coded, so it will take advantage of intellisense, refactoring, and error checking at compilation time.

Routing in Asp.Net MVC is accomplished in many (and more elaborate) ways like attribute routing. Some aspects make this routing style less appealing to me:

  • Attribute routing is decentralized, so cannot be easily managed (doubles or omissions in routes)
  • Template based routing is based on parsed strings, so there's no way to use intellisense, refactoring or compile time error checking (though at startup some problems are reported)
  • Templates with {controller} and {action} parameters are IMO to greedy and error prone (if not a security risk)
  • Reading and interpreting routes is not easy (especially with constraints and regexps)

I know it's possible to define explicit routes like:

routes.MapRoute(name:"CustomerList", template:"api/customer",defaults: new { controller = "Customer", action = "Get" }); 

But I'm not sure that's like swimming against the tide and I don't know the impact on performance.

Therefor my question: is there a more Express-like routing style possible and feasible in Asp.Net? Or would you suggest an other approach (preferably with key aspects "centralized", "not string-based")

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!