Asp.Net Routing - Display complete URL

后端 未结 3 745
臣服心动
臣服心动 2020-12-04 02:33

I have a domain \"http://www.abc.com\". I have deployed an ASP.net MVC4 app on this domain. I have also configured a default route in RouteConfig.cs as shown below



        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 02:38

    One option would be to set your default route to a new controller, maybe called BaseController with an action Root:

    public class BaseController : Controller
    {
        public ActionResult Root()
        {
            return RedirectToAction("Home","MyApp");
        }
    }
    

    and modify your RouteConfig to point to that for root requests:

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

提交回复
热议问题