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:
- remove reference microsoft.identitymodel.* assemblies in project
- add reference system.identitymodel & system.identitymodel.services assemblies
- fix using statements
- 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
Post a Comment