Identity is not IClaimsIdentity using WIF (on ASP.NET MVC 4 / Azure)

北城以北 提交于 2019-12-04 09:23:34

When running locally (on a Windows 8 Release Preview machine), the following code does work:

<p>Authenticated: @User.Identity.IsAuthenticated</p>
<p>Name: @User.Identity.Name</p>
@{
    dynamic identity = User.Identity;
    <table>
        <tr>
            <th>Type</th><th>Value</th><th>Issuer</th><th>Original Issuer</th>
        </tr>
        @foreach (var claim in identity.Claims)
        {
            <tr>
                <td>@claim.Type</td><td>@claim.Value</td><td>@claim.Issuer</td><td>@claim.OriginalIssuer</td>
            </tr>
        }
    </table>
}

This leads me to believe that the WIF tools for VS2012RC only support .NET 4.5 as a target.

When running locally, the actual runtime is .NET 4.5, which has core identity changes related to WIF (compare this diagram for .NET 4.0 with this diagram for .NET 4.5). So, by using dynamic (and changing ClaimType to Type), I'm able to access the .NET 4.5 WIF runtime locally (even though the project targets .NET 4.0).

I tried deploying to the cloud, but the app complained about not finding System.IdentityModel.Services.dll (since Azure only uses .NET 4.0 currently). Not too big of a deal for me since I don't plan on deploying until .NET 4.5 is out.

I think you are missing the WIF modules in ASP.NET config for "classic" mode (not sure how you are running the app). Try adding these:

 <system.web>
    <httpModules>
          <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>...
 </system.web>

See here for more details on HTTP Modules in classic and integrated modes: http://msdn.microsoft.com/en-us/library/ms227673.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!