Reputation: 275
I'm using asp.net mvc 4 with razor syntax
I want to How to allow users to only edit their Data using session
I tried that :
@model ProcRec.Models.Candidat
@{
if (Session["ID"] != Model.Id.ToString())
{
Session.Abandon();
Response.Redirect("~/Candidat/LoginCandidat");
}
but it's not working ( Session["ID"] != Model.Id.ToString() always true. )
Upvotes: 1
Views: 135
Reputation: 324
use this :
@model ProcRec.Models.Candidat
@{
if (!Session["ID"].Equals(id.ToString()))
{
Session.Abandon();
return RedirectToAction("LoginCandidat", "Candidat");
}
because your session["ID"] is typed as object not as a string ( == is used to compare strings that are typed as string .....)
Upvotes: 2