skip to Main Content

When i redirect from a Controller using

RedirectToAction("Index", "Controller");

Or Generate a link with UrlHelper

@Url.Action("Index","Controller");

In both ways the “/Index” Part is striped down from my URL.
Although for SEO Purposes i want my url to be displayed always at the same manner.

www.domain.com/en/Controller/Index

but now i get

www.domain.com/en/Controller

How can i force these two methods above always display the “/Index” Part.

P.S I know this happens because “Index” is indicated as a Default action on my route, but either way i want it to be displayed.

3

Answers


  1. Check your configuration inside global.asax file. It can be like this.

     public static void RegisterRoutes(RouteCollection routes)
     {
                routes.MapRoute(
                    "Default", // Route name
                    "{controller}/{action}/{id}", // URL with parameters
                    new { controller = "Controller", action = "Index", id = UrlParameter.Optional });
      }
    

    Maybe based on your mask you always going to default route. So just remove default mapping.

    Login or Signup to reply.
  2. Add new role in RouteConfig with before default route with Index action

    routes.MapRoute(
                name: "DefaultIndex",
                url: "{controller}/Index/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
    
    Login or Signup to reply.
  3. You can try do this:

     public class HomeController : Controller
     {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
    
            return RedirectToAction("About","Home");
        }
    
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";
    
            return View();
        }
    
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
    
            return View();
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search