Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich is more secure to pass the Object ID as a hidden field in the form or to pass it in the request itself
    primarykey
    data
    text
    <p>i have the following edit view which contains a hidden field which contains the object ID:-</p> <pre><code>@model Elearning.Models.Class @{ ViewBag.Title = "Edit"; } @section scripts{ &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/WordCount.js")" type="text/javascript"&gt;&lt;/script&gt; } &lt;h2&gt;Edit123&lt;/h2&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Class&lt;/legend&gt; @Html.HiddenFor(model =&gt; model.ClassID) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ClassName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.ClassName) @Html.ValidationMessageFor(model =&gt; model.ClassName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ManagedBy) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.ManagedBy, new { value = "FL", disabled = "disabled" }) @Html.ValidationMessageFor(model =&gt; model.ManagedBy) &lt;/div&gt; @Html.HiddenFor(model =&gt; model.Timestamp) &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } &lt;div&gt; @Html.ActionLink("Back to Class List", "Index") &lt;/div&gt; </code></pre> <p>this view will be rendered using the following link:-</p> <pre><code>@Html.ActionLink("Edit", "Edit", new { id = item.ClassID }) </code></pre> <p>my edit action method signature look as the following which will not use the hidden field value:-</p> <pre><code>[HttpPost] public ActionResult Edit(int id, FormCollection colletion) { Class c = elearningrepository.GetClass(id); //code does here </code></pre> <p>i can also write the action method as follow which accept the value of the hidden field:-</p> <pre><code>[HttpPost] public ActionResult Edit(int ClassID, FormCollection colletion) { Class c = elearningrepository.GetClass(Classid); //code does here </code></pre> <p>so which apprach is more secure (if any ) passing the object ID as a hidden field OR passing it from the <code>Html.ActionLink</code> ? BR</p> <p><strong>Edit:-</strong> i am checking if the user who will edit the object is <code>IsManagedBy(User.Identity.Name)</code> before updating the object as follow:-</p> <pre><code> [HttpPost] public ActionResult Edit(int id, FormCollection colletion) { Class c = elearningrepository.GetClass(id); if (!c.IsManagedBy(User.Identity.Name)) { return View("Error"); } try { if (TryUpdateModel(c)) { // elearningrepository.setmod(c); elearningrepository.Save(); return RedirectToAction("Details", new { id = c.ClassID }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload