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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -