次のプロパティを持つ Visit という名前のオブジェクトがあります:-
注 DoctorID VisitTypeID CreatedBy Date VisitID PatientID StatusID タイムスタンプ
編集ビューでは、ユーザーは次の 2 つのプロパティのみを編集できます。
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Visit</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Note)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Note)
@Html.ValidationMessageFor(model => model.Note)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DoctorID)
</div>
<div class="editor-field">
@Html.DropDownList("DoctorID", String.Empty)
@Html.ValidationMessageFor(model => model.DoctorID)
</div>
<p>
@Html.HiddenFor(model => model.VisitTypeID)
@Html.HiddenFor(model => model.CreatedBy)
@Html.HiddenFor(model => model.Date)
@Html.HiddenFor(model => model.VisitID)
@Html.HiddenFor(model => model.PatientID)
@Html.HiddenFor(model => model.StatusID)
@Html.HiddenFor(model => model.timestamp)
<input type="submit" value="Create" />
編集ビューにすべてのプロパティを含める必要があります。これは、Visit オブジェクトを編集後のアクション メソッドに渡すためです。次のようになります。
[HttpPost]
public ActionResult Edit(Visit visit)
{
if (!(visit.Editable(User.Identity.Name)))
{
return View("NotFound");
}
try
{
if (ModelState.IsValid)
{
repository.UpdateVisit(visit);
repository.Save();
return RedirectToAction("Index");
}
}
catch (DbUpdateConcurrencyException ex)
{
var entry = ex.Entries.Single();
var clientValues = (Visit)entry.Entity;
ModelState.AddModelError(string.Empty, "The record you attempted to edit "
+ "was modified by another user after you got the original value. The "
//code goes here
したがって、これらの理由から上記のアプローチについて心配しています:- 1. 攻撃者が hiddenfields の値を変更する可能性があります。2. Visit モデル クラスで [Bind(Include = "....")] を定義できません。
したがって、このアプローチを引き続き使用する必要があるかどうか、または従うべきより良いアプローチがあるかどうかを判断できません