【发布时间】:2015-09-09 20:57:11
【问题描述】:
目前在我的 rewriterules.config 中,我设置了以下规则:
<rule name="PublicUrl" stopProcessing="true">
<match url="^public-url.html$" />
<action type="Rewrite" url="public-url.html?query=string" />
</rule>
我使用的是 MVC 版本 4,想知道是否有办法在 RouteConfig.cs 中添加查询字符串(向后兼容所需),而不是在 rewriterules.config 中添加。
控制器中的动作结果如下所示:
public ActionResult Test(string strParam)
{
return View("BuildingListingPage");
}
RouteConfig.cs 中的路由如下所示:
routes.MapRoute(
name: "Publicurl",
url: " public-url.html ",
defaults: new { controller = "Home", action = "Test", strParam = "hi there”, querystring = "addme" }
);
我在这里的尝试是将默认值中的查询字符串附加到查询字符串变量中。如果我要从视图中使用 actionlink 或 URLHelper,我相信不匹配的参数确实会附加到查询字符串中。
我还尝试创建一个实现 RouteBase 的自定义类并将值添加到 RouteValue,但这并没有实现我的目标。
这里的问题是,是否有办法从 Routeconfig.cs 中将变量附加到查询字符串变量。
【问题讨论】:
标签: c# asp.net-mvc