0

Scenario: We have MVC 4.0 web application with display myOrders which returns json result with historical data.

This action will be called by JQUERY Ajax from front end.

Problem: Is there anyway we can authentication and make sure that the orderID passed from JQuery Ajax front end belongs to logged in user?

Thanks heaps.

1 Answer 1

1

I usually do it in this way. Probably your Order record should have a CreatedById field where you store the ID of the user who created it. When you get the OrderID from the Ajax call in your action method, build an Order object from that ID and check what is the CreatedByID value. Compare it with the current logged in UserId( you may have it in the session ?) and the decide whether to show the page to the user.

Some thing like this.

public ActionResult GetOrder(int id)
{
  Order objOrder=OrderService.Get(id);
  if(objOrder.CreatedById==GetCurrentLoggedInUserId())
  {
    return View(objOrder);
  }
  else
  {
    return View("NotYours");
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.