c# - How to customize MVC url path -


i trying create clean url path mvc controller , need little assistance.

example desired path: http://www.linkedin.com/in/alumcloud. path linkedin , notice how has /in/alumcloud.

i mine read: http://www.alumcloud.com/alumcloud/somecompanyname

how mvc controller?

below code in mvc controller, becuase controller needed respond get http methods.

public class alumcloudcontroller : alumcloudmvccontrollerbase {     // get: /alumcloud/details/5     public actionresult details(string companyname)     {         return view();     } } 

--here routeconfig

public class routeconfig {     public static void registerroutes(routecollection routes)     {          routes.ignoreroute("{resource}.axd/{*pathinfo}");          routes.maproute(             name: "default",             url: "{controller}/{action}/{id}",             defaults: new { controller = "home", action = "index", id = urlparameter.optional }         );     } } 

-----------------------------------2nd attempt------------------------------------

--route code 2

public static void registerroutes(routecollection routes)         {             routes.ignoreroute("{resource}.axd/{*pathinfo}");              routes.maproute(                 name: "default",                 url: "{controller}/{action}/{id}",                 defaults: new { controller = "home", action = "index", id = urlparameter.optional }             );              routes.maproute(                 name: "public",                 url: "ac/{companyname}",                 defaults: new { controller = "alumcloudcontroller", action = "userprofile" }             );  } 

--controller code 2

public class alumcloudcontroller : alumcloudmvccontrollerbase {     // get: /alumcloud/details/5     public actionresult userprofile(string companyname)     {         return view();     } } 

--the url

'/ac/' + options.person.companyname  

--snap shot of 404 error

404 mvc error

try adding route above default:

routes.maproute(     name: "profile",     url: "alumcloud/{companyname}",     defaults: new { controller = "alumcloudcontroller", action = "details" } ); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -