Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用两个参数在asp.net 4.0中重写url_Asp.net_C# 4.0_Url Rewriting_Url Routing - Fatal编程技术网

使用两个参数在asp.net 4.0中重写url

使用两个参数在asp.net 4.0中重写url,asp.net,c#-4.0,url-rewriting,url-routing,Asp.net,C# 4.0,Url Rewriting,Url Routing,我几乎没有像这样动态生成的URL 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

我几乎没有像这样动态生成的URL

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实现这一点请帮助我
谢谢你

在你的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"
        );
    }
如果我只能在没有任何参数的情况下调用,它会在路由中使用相同的规则定义吗?