【发布时间】:2016-05-12 21:27:32
【问题描述】:
我需要在返回视图之前对 id 进行编码。传入 url 时很容易猜到 id,所以我尝试在返回 View 之前进行编码
[HttpGet]
public ActionResult Index(int id = 0)
{
var model = new ReviewModel();
if (id != 0)
{
model.Id = id;
model = model.Get();
//How can I encode model.Id here***
}
ViewBag.IsAdmin = model.IsAdmin(User.Identity.Name);
model.SaveAudit("Visits Code of Conduct", User.Identity.Name);
return View(model);
}
【问题讨论】:
-
不要使用不断增长的数字 ID,而是使用哈希值来识别您的模型实体。您需要将这些哈希值与其他模型属性一起存储。
-
顺便说一句,您的
Index操作无关紧要,除了将int id更改为string hash或类似的东西外,它将保持不变。重要的部分是创建和保存模型实体的位置。在这样的地方,您必须创建实体的哈希。其余的保持不变。 -
如果没有您发布的代码,这个问题也不会有所不同。你基本上是在要求人们做你的功课。
标签: c# asp.net asp.net-mvc razor