thank you!!
i have question.
the redirecttoaction won't work, runs not route url
it runs edit controller first
public actionresult edit(int? id) { checkaccess(); if (id == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } ..... }
it access checkaccess() method, when runs return redirecttoaction("error", "index"); runs ok not route url, , "edit" controller , run next command "if (id==null).
public actionresult checkaccess() { int staffusertype = 5; if (session["staffusertype"] != null) staffusertype = convert.toint32(session["staffusertype"]); if (staffusertype == 5) { //return json(url.action("index", "error")); return redirecttoaction("error", "index"); //return view("errorcontroller/index"); } else return view(); } }
the edit() never return redirecttoaction result, because return values checkaccess() isn't captured , returned.
you modify checkaccess() return bool
public bool checkaccess() { int staffusertype = 5; if (session["staffusertype"] != null) staffusertype = convert.toint32(session["staffusertype"]); if (staffusertype == 5) { return false; } else { return true; } }
then check result in edit, , return redirecttoaction if result false.
public actionresult edit(int? id) { if (!checkaccess()) { return redirecttoaction("index", "error"); } ..... }
Comments
Post a Comment