【发布时间】:2010-12-16 21:52:15
【问题描述】:
如果我有这条路线:
routes.MapRoute(
"BlogRoute", // Route name
"blog/{action}", // URL with parameters
new { controller = "Blog", action = "Index", id="abc" } // Parameter defaults
);
...并在控制器中使用此 Index 方法:
public ActionResult Index(string id)
{
return View((object)id);
}
是否有人可以将该 id 参数从“abc”更改为其他值?例如,通过将 ?id=somethingElse 附加到 URL?我试过了,但它没有改变它。那么是否保证我在 Index 方法中总是会得到“abc”?
基本上我需要在选择一个路由时发送一个硬编码字符串,并且我不希望用户能够通过 URL 或任何其他机制更改此字符串。这就像“abc”是一个密码(它不是但只是假设它是)。只有开发者可以通过编辑 Global.asax.cs 来设置这个字符串。
有可能吗?
【问题讨论】:
标签: asp.net-mvc routing asp.net-mvc-routing