Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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
.net 向url添加字符串_.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

.net 向url添加字符串

.net 向url添加字符串,.net,asp.net-mvc,asp.net-mvc-4,.net,Asp.net Mvc,Asp.net Mvc 4,我有一个应用程序根:localhost/Product 我想在我的根url上附加一个字符串 localhost\stringName stringName将被读取到frm配置文件并设置为url的末尾,后跟控制器和操作名称 例如:localhost\Product\stringName\controller\Action stringName需要在整个应用程序中与所有重定向一起保留 请帮助签出: 您需要对自定义url路由进行一些研究您可以这样更改默认路由: routes.MapRoute(

我有一个应用程序根:localhost/Product

我想在我的根url上附加一个字符串 localhost\stringName

stringName将被读取到frm配置文件并设置为url的末尾,后跟控制器和操作名称 例如:localhost\Product\stringName\controller\Action stringName需要在整个应用程序中与所有重定向一起保留

请帮助签出:


您需要对自定义url路由进行一些研究

您可以这样更改默认路由:

routes.MapRoute(
     name: "Default",
     url: "{controller}/stringName/{action}/{id}",
     defaults: new { controller = "DefaultPage", action = "Index", id = UrlParameter.Optional }
);
从RouteConfig.cs文件中。 或者,如果您将应用程序从MVC4升级到MVC5,您可以使用属性routing,您可以阅读更多内容

更新:

在默认路由中尝试以下操作:

string stringName = WebConfigurationManager.AppSettings["stringName"].ToString()
routes.MapRoute(
    name: "Default",
    url: stringName + "/{controller}/{action}/{id}",
    defaults: new { controller = "Page", action = "Index", id = UrlParameter.Optional }
);
);

上述路由将不匹配,因为..我的请求没有以stringName开头..它将添加到global.asax中的sessionStart上。然后您可以像下面这样实现IRouteConstraint: