Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC default path

I am trying to figure out how to route my application to a default controller/task/id when none is specified in a request.

Here is my one routing instruction...

 routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new
    {
     controller = "LML",
     action = "TaskLibrary",
     id = 7
     //id = UrlParameter.Optional
    } // Parameter defaults
   );

Using this, if I enter in 'http://mywebsite/', the proper controller/action/id is called. However, I would like the URL to reflect this. Rather the URL remains untouched from what I entered.

Using routing, is there a way to affect the URL so that it redisplays synced with the controller/action/id it is showing by default? Or do I have to create some sort of redirect action?

like image 983
John Livermore Avatar asked Dec 06 '25 12:12

John Livermore


1 Answers

Routing is about mapping a request to an action, not about redirecting.

You could change your default route parameters to default to another action that simply redirects to "LML/TaskLibrary/7"

like image 181
Phil Avatar answered Dec 08 '25 03:12

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!