I have a problem with MVC routing, it normally works great but for some reason the statement in the middle works fine but the last route does not work. If I put the third route in the middle it will work fine. I don’t know why these two routes are interferring with each other.
Here are the routes:
routes.MapRoute(
"VoucherPreviewNdddewUser", // Route name
"{Home}/{VoucherBusinessUserEntry}/{ID}/{TokenID}", // URL with parameters
new { controller = "Home", action = "VoucherBusinessUserEntry", id = 0, TokenID = Guid.NewGuid() } // Parameter defaults
);
routes.MapRoute(
"Regdfsdfsdf", // Route name
"{LoginReg}/{Register}/{UserTrackingID}/{IsFromScript}", // URL with parameters
new { controller = "LoginReg", action = "Register", UserTrackingID = System.Guid.Empty
,isfromscript = System.Boolean.FalseString
} // Parameter defaults
);
Here are the Url’s:
http://localhost:50839/home/VoucherBusinessUserEntry/44/7209FA62-FD5F-40AE-8239-7CF1855675E8
http://localhost:50839/LoginReg/Register/7209FA62-FD5F-40AE-8239-7CF1855675E8/true
Does anyone have any ideas what might be causing this?
When you put something between {} that becomes a variable. So your routes should really look like this:
You still need to define which controller and action you want, but those variables are no longer present in the URL as they are constants and not up for debate. If you want them to be variable, then you need {controller} and {action} in the URL, with defaults of, for example,
LoginRegas in the second route.