Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 Routing Exception Handling based on UserId
    primarykey
    data
    text
    <p>Trying to build out an exception if move.UserId does not equal currentUserId then Redirect to Action else if move.UserId does equal currentUserId return View.</p> <p>See code here:</p> <pre><code>public ActionResult Details(int id) { MembershipUser currentUser = Membership.GetUser(); Guid currentUserId = (Guid)currentUser.ProviderUserKey; Move move = db.Moves.Where(m =&gt; m.UserId == currentUserId) .FirstOrDefault(); if (currentUser != null &amp;&amp; currentUser.ProviderUserKey != null &amp;&amp; currentUser.IsApproved) { if (move.UserId == currentUserId) { return View(move); } } return RedirectToAction("Oops", new RouteValueDictionary( new { controller = "Account", action = "Oops", area = "", id = UrlParameter.Optional })); } </code></pre> <p>I would like to tie it to the url which will bring back Move/(int) so that if the user modifies this to an (int) that returns a move where move.UserId != currentUserId then they also redirect. Currently they can modify Url to obtain other's moves.</p> <h1>MyController</h1> <pre><code> public ViewResult Index() { if (User.Identity.IsAuthenticated) { MembershipUser currentUser = Membership.GetUser(); Guid currentUserId = (Guid)currentUser.ProviderUserKey; if (currentUser != null &amp;&amp; currentUser.ProviderUserKey != null &amp;&amp; currentUser.IsApproved) { var results = db.Moves.Where(move =&gt; move.UserId == currentUserId) .ToList(); return View(results); } } return View(db.Moves.ToList()); } [ClientValidation] public ActionResult Details(Move move) { return View(move); } </code></pre> <h1>MyView</h1> <pre><code>@model MovinMyStuff.Domain.Entities.Move @{ ViewBag.Title = "Details"; } &lt;div&gt; @Html.DisplayFor(model =&gt; model.StartCity), @Html.DisplayFor(model =&gt; model.StartState) @Html.DisplayFor(model =&gt; model.StartZip) - @Html.DisplayFor(model =&gt; model.EndCity), @Html.DisplayFor(model =&gt; model.EndState) @Html.DisplayFor(model =&gt; model.EndZip) &lt;/div&gt; &lt;fieldset&gt; &lt;div class="job-details"&gt; @Html.HiddenFor(model =&gt; model.MoveId) @Html.HiddenFor(model =&gt; model.UserId) &lt;ul class="distance"&gt; &lt;li&gt; &lt;div&gt; Distance&lt;/div&gt; &lt;/li&gt; &lt;li&gt;1,978.6 Miles&lt;/li&gt; &lt;/ul&gt; &lt;ul class="address-wrapper"&gt; &lt;li&gt; &lt;ul class="address from"&gt; &lt;li&gt; &lt;div&gt; From&lt;/div&gt; &lt;/li&gt; &lt;li&gt;&lt;span&gt;Address: &lt;/span&gt; @Html.DisplayFor(model =&gt; model.StartStreetNumber) @Html.DisplayFor(model =&gt; model.StartStreetName) &lt;/li&gt; ... &lt;/fieldset&gt; </code></pre>
    singulars
    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.
 

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