简体   繁体   English

如何只允许用户编辑其数据

[英]How to allow users to only edit their Data

I'm using asp.net mvc 4 with razor syntax 我正在使用带有剃刀语法的asp.net mvc 4

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. ) 但它不起作用(Session [“ ID”]!= Model.Id.ToString()始终为true。)

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 .....) 因为您的session [“ ID”]被键入为对象而不是字符串(==用于比较键入为字符串.....的字符串)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM