-1

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.

6
  • Why do you want to include that for SEO purposes? A simpler URL will be far more important for SEO. Commented Dec 22, 2016 at 14:08
  • mostly because i have manually generated rel="canonical" tags that i want to be matched. Commented Dec 22, 2016 at 14:12
  • yes you are right. I could not find your linked answer before. Commented Dec 22, 2016 at 14:28
  • @Anestis Kivranoglou Is your problem solved with new route role ? Commented Dec 22, 2016 at 14:48
  • Although it is a solution it adds 1 extra route as burden , i am still looking for alternatives. Commented Dec 22, 2016 at 15:43

3 Answers 3

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 }
        );
Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

You need to have some default route. If you removed all of them, nothing would work.
You can map to your strict url if you need.
0

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();
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.