asp.net mvc 4 - Unable to cast object of type System.Security.Claims.ClaimsPrincipal to type Microsoft.IdentityModel.Claims.IClaimsPrincipal -


i developing 1 mvc4 application authenticate corp domain users using adfs , have written code , getting error below, not getting claims ?

system.invalidcastexception: unable cast object of type 'system.security.claims.claimsprincipal' type 'microsoft.identitymodel.claims.iclaimsprincipal'.

    public actionresult index()     {         try         {              iclaimsprincipal principal = (iclaimsprincipal)thread.currentprincipal;             iclaimsidentity identity = (iclaimsidentity)principal.identity;             if (string.isnullorempty(identity.claims[0].value.split('@')[0]))             {                 viewdata["message"] = string.format("you email :{0}", identity.claims[0].value.split('@')[0]);              }             else             {                 viewdata["message"] = "you not getting claims";             }         }         catch (exception ex)         {             viewdata["message"] = "something wrong.";         }         return view();     } 

what observe result of mixing .net 3.5 wif (microsoft.identitymodel) , wif 4.0 (system.identitymodel & system.security). suggest is:

  1. remove reference microsoft.identitymodel.* assemblies in project
  2. add reference system.identitymodel & system.identitymodel.services assemblies
  3. fix using statements
  4. fix references microsoft.identitymodel in web.config

do backup copy of project before doing this, because, if haven't done before, might end lot of error , not working code. main idea have rid of , microsoft.identitymodel references , good.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -