How to hide the controller name in Url?

How to hide the controller name in Url?

I am using ASP.NET MVC.

Original url: http://www.sample.com/Users.mvc/UserDetail/9615

"Users" is the name of the controller, "UserDetail" is the name of the action, and "9615" is the UserId.

How to hide the controller name and action name in the url.

Similarly: http://www.sample.com/9615

I wrote the following code in the Global.ascx.cs file to hide the name of the action:

routes.MapRoute(
             "UserDetail",             // Route name
             "Users.mvc/{UserId}",              // URL with parameters
             new { controller = "Users", action = "UserDetail", UserId = "" }  // Parameter defaults
            );

Using the code above, I hid the action name and got this URL: http://www.sample.com/Users.mvc/9615

But how can I hide the controller name and get this url: http://www.sample.com/9615

Thank.

+1
2

. , . - , IIS, , www.xyz.com/1234 ASP.NET. IIS7, IIS6, , ASP.NET.

, . http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx ( "URL- IIS6" )

:

routes.MapRoute("UserDetails", "{UserID}/{*name}", 
    new { controller = "Users", action = "UserDetail" , UserID=""});

.

+4

MVC "{UserID}" "{id}", , "{UserID}" URL, , . , "id", , "UserDetails", idID, UserID. , formate :

routes.MapRoute("UserDetails",
       "{UserID}",
       new { controller = "Users", action = "UserDetail", id = "" }
);
routes.MapRoute(
       "Default", // Route name
       "{controller}/{action}/{id}", // URL with parameters               
       new { controller = "Account", action = "LogOn", id = "" } // Parameter defaults   
);
+2

All Articles