特殊角色?在routes.MapRoute url参数.Net MVC 4中
我建立了一个新的网站,我想保留旧的链接只是为了做一个永久的重定向。 为此,我编写了一个新的控制器特殊角色?在routes.MapRoute url参数.Net MVC 4中,.net,asp.net-mvc-4,asp.net-mvc-routing,.net,Asp.net Mvc 4,Asp.net Mvc Routing,我建立了一个新的网站,我想保留旧的链接只是为了做一个永久的重定向。 为此,我编写了一个新的控制器 public class RedirectController : Controller { // // GET: /Redirect/ public ActionResult Index() { return RedirectPermanent("~/"); } ... 在RouteConfig.cs中,我将路由写为
public class RedirectController : Controller
{
//
// GET: /Redirect/
public ActionResult Index()
{
return RedirectPermanent("~/");
}
...
在RouteConfig.cs中,我将路由写为
routes.MapRoute(
name: "Redirect 301 prensa",
url: "press.aspx", defaults: new { controller = "Redirect", action = "Index" }
);
用于重定向客户上缓存的旧URL
我的问题是当我想在url参数中放入特殊字符“?”时
routes.MapRoute(
name: "Redirect 301 prensa",
url: "press.aspx?id=1", defaults: new { controller = "Redirect", action = "Index" }
);
应用程序编译正常,但崩溃开始说Url不能包含?性格
我的web.config就像
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\" requestValidationMode="2.0"/>
<pages controlRenderingCompatibilityVersion="4.0" validateRequest="false"/>
写特殊角色有什么想法吗
提前感谢我认为您应该尝试重新配置路由映射,并使用通配符表达式对两条路由进行分组:
routes.MapRoute(
name: "Redirect 301 prensa",
url: "{press.aspx*}", defaults: new { controller = "Redirect", action = "Index" }
);
通过这种方式,相关的URL(press.aspx,press.asx?id=1 press.asxpAnything)将被重定向到同一位置
并检查web.config中的requestPathInvalidCharacters以允许使用字符“?”和可能的“&”