-4

i am working on a web project in asp.net mvc. This is code in my RouteConfig

This is url

localhost:55960/Home/myAction/80102/Aus-won-the-match-by-9-wickets

but i want to make it like

localhost:55960/myAction/80102/Aus-won-the-match-by-9-wickets

 routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}/{Title}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, Title = "" }
                );

I have applied many suggestions available on this platform but not worked. Is there any one who can explain in detail

2
  • What is the motivation behind your question? Are you trying to obfuscate the code-level name of a controller or are you trying to simplify the URL as per Isaack Rasmussen's answer? Commented Aug 16, 2017 at 14:14
  • this is your answer: stackoverflow.com/questions/57799273/… Commented Sep 7, 2019 at 4:51

1 Answer 1

1

So you want your controller to be at the root, like domain.com/?id=1 or domain.com/list?id=1 instead of domain.com/controller/list?id=1 ?

You can add to your config

config.MapHttpAttributeRoutes();

Then for that controller,

[RoutePrefix("")]
public class HomeController : Controller

But this may get confusing to keep track of if you have many controllers. And it may be better to configure routes.MapRoute() to point to a default controller

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.