【发布时间】:2016-04-05 02:27:02
【问题描述】:
我已经在 Home 控制器中声明了 Index 操作:
[HttpGet]
public ActionResult Index(string type)
{
if (string.IsNullOrEmpty(type))
{
return RedirectToAction("Index", new { type = "promotion" });
}
return View();
}
接受:
https://localhost:44300/home/index?type=promotion
和
https://localhost:44300/?type=promotion
在我为 404 页面配置路由之前一切正常:
routes.MapRoute(
name: "homepage",
url: "home/index",
defaults: new { controller = "Home", action = "Index" }
);
routes.MapRoute(
name: "default",
url: "/",
defaults: new { controller = "Home", action = "Index" }
);
routes.MapRoute(
"404-PageNotFound",
"{*url}",
new { controller = "Error", action = "PageNotFound" }
);
语法无效:
路由 URL 不能以 '/' 或 '~' 字符开头,也不能 包含一个“?”字符。
如果我删除第二个配置,
https://localhost:44300/?type=promotion
不会被接受。 -> 显示 404 页面。
我的问题是:有没有办法配置以“/”开头的路由 URL(无控制器,无操作)?
【问题讨论】:
-
@MusicLovingIndianGirl 你看清楚我的问题了吗?
-
@MusicLovingIndianGirl 不重复。请重新打开
标签: c# asp.net-mvc routes url-routing asp.net-mvc-routing