2

we have one project in asp.net mvc 5 when i run my project and click on some button for go to the next page then we are getting the url like wwww.abx.com/project/projectname .

where project is my controller name and projectname is Action name

so if i want so url like

wwww.abx.com/projectname

then this is possible ?

please if any one have some solution so please give it

here is my route.config file code

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

Thanks

2 Answers 2

0

you have to create a new route:

public static void RegisterRoutes(RouteCollection routes){
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "ProjectName1",
url: "Projectname1",
defaults: new { controller = "Project1", action = "Projectname1" }
);

routes.MapRoute(
name: "ProjectName2",
url: "Projectname2",
defaults: new { controller = "Project2", action = "Projectname2" }
);

routes.MapRoute(
name: "ProjectName3",
url: "Projectname3",
defaults: new { controller = "Project3", action = "Projectname3" }
);



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


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

3 Comments

we want for more then 5 pages.
wwww.abx.com/project/projectname1 wwww.abx.com/project/projectname2 wwww.abx.com/project/projectname3 wwww.abx.com/project/projectname4 wwww.abx.com/project/projectname5 and i want like wwww.abx.com/projectname1 wwww.abx.com/projectname2 wwww.abx.com/projectname3 wwww.abx.com/projectname4 wwww.abx.com/projectname5
Check it please.
0

If you would like to do this for only one controller - add a custom route as suggested by @Hamed Javaheri, or use attribute mapping as described here

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Project",
                url: "projectname",
                defaults: new { controller = "project", action = "projectname", id = UrlParameter.Optional }

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

If you want this to work for many / most routes then you might want to change the default mapping, somethin similar to this question:

ASP.NET MVC Default URL View and

ASP.NET MVC Routing with Default Controller

 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{action}",
                defaults: new { controller = "project", id = "" }
            );
        }

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.