【问题标题】:difference between URL rewriting and URL routing mvcURL重写和URL路由mvc的区别
【发布时间】:2017-04-08 15:52:00
【问题描述】:

我正在尝试学习 MVC,在理解 MVC 中 URL 重写和 URL 路由之间的区别时需要帮助。

【问题讨论】:

    标签: model-view-controller url-rewriting url-routing


    【解决方案1】:

    URL Routing 是 MVC 完成的路由,当我们在 url 空间中输入内容时,它会首先调用

    RouteConfig.RegisterRoutes(RouteTable.Routes);
    

    在 Global.asax.cs Application_Start() 方法中,如果你在其中放置一个断点,那么你可以理解路由方法,然后它会调用

     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 }
                );
            }
    

    在 App_start=>RouteConfig 类中,您可以在此处找到 RegisterRoutes 方法。在这里我们可以定义我们的 url 的结构,在这里它将决定应该调用哪个控制器和动作。 这个过程就是url路由

    URL 重写是整个 diff 概念 假设我们的控制器名称是 Customer,动作名称是 Login 当我们运行应用程序时,我们的 url 将如下所示 http://Localhost:233/Customer/Login 但客户端仅结束 http://Localhost:233/Login,用于 SEO 目的 为了实现这一点,我们必须通过保持相同的控制器和动作名称来重写 url 要了解有关 url 重写的更多信息,我已经在 http://grandhah.blogspot.in/2015/07/url-rewriting-in-mvc-4-attribute-routing.html 中解释了属性重写,请访问并让我知道您已经足够清楚了.. 美好的一天

    【讨论】:

      猜你喜欢
      • 2013-01-19
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2019-02-24
      • 1970-01-01
      • 2010-09-10
      • 2012-02-04
      • 2014-04-23
      相关资源
      最近更新 更多