Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda