How to hide controller name in Url?

后端 未结 2 802
梦谈多话
梦谈多话 2021-01-16 14:25

How to hide controller name in Url?

I use the ASP.NET MVC.

The original url is: http://www.sample.com/Users.mvc/UserDetail/9615

The \"Users\" is con

2条回答
  •  再見小時候
    2021-01-16 14:36

    The idea is the same. You do just the thing you did to the action. However, your problem arises from the fact that IIS is probably not mapping www.xyz.com/1234 to ASP.NET runtime. To do so in IIS7, enable integrated mode and in IIS6, add a wildcard mapping in handler map that maps everything to ASP.NET.

    To add a wildcard map, see http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx (Search for "IIS6 Extension-less URLs" in that page)

    After that, simply add a route:

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

    This should do the trick.

提交回复
热议问题