locked
Routing in MVC5 - Using RouteConfig.cs alone - is this possible ? - Part 2 RRS feed

  • Question

  • User-973886032 posted

    Hello guys

    sequel to this problem I posted here https://forums.asp.net/t/2172247.aspx?Routing+problems+in+MVC5+in+the+RouteConfig+cs+file 

    I submitted the solution to the architect who rejected it, saying he does not want to make any major changes by adding route attributes. So I am thinking is it possible to keep strict routing in just the RouteConfig.cs as the current system is undergoing a major overhaul and migration to .net core and he does not want my solution

    Once again problem is 

    routes.MapRoute(            
    name: "Login",            
    url: "{RouteId}/{language}/Login/Login",
     defaults: new { controller = "Login", action = "Index"}        
    );
    
    // and 
    
    routes.MapRoute(            
    name: "Login.aspx",            
    url: "{RouteId}/{language}/Login/Login.aspx",
     defaults: new { controller = "Login", action = "Index"}        
    );

    Now management dont want that, as they only want just one. www.domain.com/login or www.domain.com/login.aspx currently we get "TWO" additional www.domain.com/login/login.aspx and www.domain.com/login/login 

    NOw using just the RouteConfig.cs file, is it possibe to restrict the login page to just one url ?

    kind regards

    Ehi

    Tuesday, November 17, 2020 2:32 PM

Answers

All replies

  • User-474980206 posted

    you question makes little sense. if you don't want /login/login.aspx, why add that route? also what are {RouteId}/{language}, they are not in the sample url.  www.domain.com/login/login

    correctly identity the routes you want to work with url that match the route map. also show the default route as that allows the login controller to be called. 

    to prevent the default allowing the login controller, just define a custom constraint.

    remember, the route maps do not look at the controllers and actions. they only do pattern matches using data on the url, and use the first match.

    Tuesday, November 17, 2020 7:09 PM
  • User-973886032 posted

    bruce (sqlwork.com)

    you question makes little sense.

    I am with you, I dont agree with the architect (and made it clear diplomatically to my manager), but for now, I am searching maybe I missed something.

    bruce (sqlwork.com)

    also what are {RouteId}/{language}, they are not in the sample url.  www.domain.com/login/login

    Apologies, I posted it in a hurry and was trying to remove sensitive company data. It should have read www.domain.com/route/en/login/login

    apologies

    bruce (sqlwork.com)

    just define a custom constraint.

    e.g. ???

    Tuesday, November 17, 2020 9:25 PM
  • User-474980206 posted

    if you need more strict pattern matching for routes, you use constraints. see:

      https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-a-custom-route-constraint-cs

    you don't give an example of what you are trying fix, or where it goes wrong, so we can only guess at solutions.

    note: in MVC 5, attribute routing, just dynamically updates the route maps at startup based on the attributes, so you can do the same without attributes

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2020 10:06 PM
  • User-973886032 posted

    thank you, this was helpful. But I still couldnt get it past the architect,

    thanks

    if you need more strict pattern matching for routes, you use constraints. see:

      https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-a-custom-route-constraint-cs

    you don't give an example of what you are trying fix, or where it goes wrong, so we can only guess at solutions.

    note: in MVC 5, attribute routing, just dynamically updates the route maps at startup based on the attributes, so you can do the same without attributes

    Thursday, November 19, 2020 10:38 AM