asp.net mvc - redirecting using roles not working -


[validateantiforgerytoken]

    [httppost]      [allowanonymous]      public    async   task<actionresult>   index    (loginmodel   model, string  returnurl)     {           if   (modelstate.isvalid)         {             var   loginbusiness =   new    loginbusiness();             var    result =  wait   loginbusiness.loguserin(model, authenticationmanager);              var   rolemanager  =  new rolemanager<microsoft.aspnet.identity.entityframework.identityrole>(new rolestore<identityrole>(new datacontext()));             var role = await rolemanager.roleexistsasync(model.username);              if (returnurl == null && role)             {                 if (user.identity.isauthenticated && roles.isuserinrole(model.username, "admin"))                 {                     return redirecttoaction("index", "admin");                 }                 else if (user.identity.isauthenticated && roles.isuserinrole(model.username, "driver"))                 {                     return redirecttoaction("testdriver", "drivers");                 }             }             else             {                 modelstate.addmodelerror("", "invalid username or password.");            }         }          return view(model);     } 

once user log in want redirect him different views based on roles

tried on net , previous posts nothing helped


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -