为什么会FederatedAuthentication.WSFederationAuthenticationModule是空MVC中的Azure ACS联合身份验证? [英] Why would FederatedAuthentication.WSFederationAuthenticationModule be null in MVC Azure ACS Federated Authentication?

查看:231
本文介绍了为什么会FederatedAuthentication.WSFederationAuthenticationModule是空MVC中的Azure ACS联合身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想放在一起FederatedAuthentication与.NET 4.5,MVC 4,和使用自定义服务器端的登录页面重定向活跃,使用code从<一个href=\"http://garvincasimir.word$p$pss.com/2012/04/16/tutorial-mvc-application-using-azure-acs-and-forms-authentication-part-2/\"相对=nofollow>本教程,并从这个 code样本。

I'm trying to put together FederatedAuthentication with .NET 4.5, MVC 4, and active redirect using a custom server-side login page, using code from this tutorial, and from this code sample.

重定向到我的AccountController的登录方法工作正常,方法如下:

Redirecting to the LogOn method of my AccountController works fine, and the method looks like this:

public ActionResult LogOn()
{
    HrdClient hrdClient = new HrdClient();
    WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule; /*** Fails here because this is null **/
    HrdRequest request = new HrdRequest(fam.Issuer, fam.Realm, context: Request.QueryString["ReturnUrl"]);
    IEnumerable<HrdIdentityProvider> hrdIdentityProviders = hrdClient.GetHrdResponse(request);
    ViewData["Providers"] = hrdIdentityProviders;
    return View();
}

这将失败,因为 FederatedAuthentication.WSFederationAuthenticationModule 为null。

This fails because FederatedAuthentication.WSFederationAuthenticationModule is null.

使用VS 2012,我已经运行了新的身份和访问向导(这似乎取代旧的STS对话框)。这给了我FederationMetadata的一个文件夹,这似乎正确,和我的web.config几处修改。特别是模块部分看起来是这样的:

Using VS 2012, I've run the new Identity and Access wizard (which seems to replace the old STS dialog). This has given me a folder of FederationMetadata, which appears correct, and several modifications to my Web.Config. In particular, the modules section looks like this:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
  <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
</modules>

和已经见过这么回答<一个href=\"http://stackoverflow.com/questions/8937123/federatedauthentication-wsfederationauthenticationmodule-is-null-at-runtime\">8937123和<一个href=\"http://stackoverflow.com/questions/8926099/wsfederationauthenticationmodule-redirectingtoidentityprovider-event-is-not-call\">8926099,我已经添加了以下还有:

And having seen SO answers 8937123 and 8926099, I've added the following as well:

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

最后我的NuGet包的配置显示Microsoft.IdentityModel,这是正确的MVC应用程序中引用:

And finally my nuget packages config shows Microsoft.IdentityModel, which is correctly referenced by the MVC app:

<packages>
  <package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net45" />
</packages>

我也看到<一个href=\"http://social.msdn.microsoft.com/Forums/en/windowsazuresecurity/thread/ba44f757-945c-4622-9b2d-feb9a56fe71e\"相对=nofollow>上social.msdn,这似乎只是表明STS对话框确实需要运行。这个问题

任何人都可以解释为什么 FederatedAuthentication.WSFederationAuthenticationModule 将是空的,什么我无法阻止这种情况发生?

Can anybody explain why FederatedAuthentication.WSFederationAuthenticationModule would be null, and what I can do to stop this happening?

推荐答案

我设法解决这个问题我自己,因为有与此类似上这么几个悬而未决的问题,我会离开的问题和发表我自己的答案。

I managed to fix this myself, and since there are a few unanswered questions similar to this on SO, I'll leave the question up and post my own answer.

问题是升级MVC应用程序到.NET 4.5的事情。多的WIF功能保持不变(至少在表面上),但类都移动到不同的组件。我固定在这里跟随迁移指引我的问题:<一href=\"http://msdn.microsoft.com/en-us/library/jj157089.aspx\">http://msdn.microsoft.com/en-us/library/jj157089.aspx

The issue is to do with upgrading the MVC application to .NET 4.5. Much of the WIF functionality remains the same (at least on the surface), but the classes have all moved to different assemblies. I fixed my problem following the migration guidelines here: http://msdn.microsoft.com/en-us/library/jj157089.aspx

最重要的是消除对 Microsoft.IdentityModel 包旧引用(V 3.5.0),并确保它们是由类似的参考替换为 System.IdentityModel System.IdentityModel.Services 的dll,这应该是4.0版本,而来自海关总署而不是外部包。

The most important thing is to remove old references to the Microsoft.IdentityModel package (v 3.5.0) and make sure they are replaced by similar references to the System.IdentityModel and System.IdentityModel.Services dlls, which should be version 4.0, and come from the GAC rather than an external package.

我的步骤来进行修复:


  • 清理掉所有我已经加入到web.config中的垃圾,并用默认的​​MVC配置文件重新开始。

  • 删除 Microsoft.IdentityModel 包和反引用的dll

  • 在VS 2012运行访问和身份向导

  • 复制从&LT的 System.IdentityModel.Services.WSFederationAuthenticationModule 参考; system.webServer&GT;&LT;模块&gt; &LT;&的System.Web GT;&LT;&的HttpModules GT;

  • 添加&LT;身份验证模式=表格&GT;&LT;形式loginUrl =〜/帐号/登录/&GT;&LT; /认证&GT;

  • 编译,测试,舞蹈快乐的小夹具...

  • Clean out all the junk I'd added to Web.Config and start again with a default MVC Config file.
  • Remove the Microsoft.IdentityModel package and de-reference the dll
  • Run the Access and Identity wizard in VS 2012
  • Duplicate the System.IdentityModel.Services.WSFederationAuthenticationModule reference from <system.webServer><modules> in <system.web><httpModules>
  • Add <authentication mode="Forms"><forms loginUrl="~/Account/LogOn" /></authentication>
  • Compile, test, dance little jig of delight...

和这让原本WIF3.5 / MVC3 code样品工作under.NET 4.5

And this got the original WIF3.5 / MVC3 Code Sample working under.NET 4.5

这篇关于为什么会FederatedAuthentication.WSFederationAuthenticationModule是空MVC中的Azure ACS联合身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆