【问题标题】:url rewriting in asp.net 4.0 with two parameters使用两个参数在 asp.net 4.0 中重写 url
【发布时间】:2014-08-25 22:26:08
【问题描述】:

我很少有像这样的动态生成的网址

http://localhost:35228/begineercontrols?name=untitled&id=2
http://localhost:35228/begineercontrols?name=linkbutton&id=34
http://localhost:35228/begineercontrols?name=lablebutton&id=5 

还有更多,使用路由我删除了 .aspx 扩展名,这很好,现在我想让上面的 url 更友好

http://localhost:35228/begineercontrols/untitled/2 

如何为所有动态生成的 url 实现这一点,请帮帮我 提前感谢!

【问题讨论】:

    标签: asp.net c#-4.0 url-rewriting url-routing


    【解决方案1】:

    在您的 App_Start/RouteConfig.cs 中,像这样修改代码

     public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);
            // Add Routes.
            RegisterCustomRoutes(RouteTable.Routes);
        }
    
       private static void RegisterCustomRoutes(RouteCollection routes)
        {
            routes.MapPageRoute(
                "begineercontrolsRoute",
                "begineercontrols/{name}/{id}",
                "~/begineercontrols.aspx"
            );
        }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2013-08-30
    • 2016-07-29
    相关资源
    最近更新 更多