17

是否有将 WIF 与 ASP.NET MVC 应用程序一起使用的示例应用程序?有人可以帮助我开始尝试整合这两种技术吗?

4

4 回答 4

23

我发现到目前为止最好的入门示例是 Dominick Baiers StarterSTS。

即使您不将其用作 STS,网站上的教程也是一个很好的起点。没有专门的 ASP.NET MVC 教程,但我让它的工作方式与 ASP.NET WebForms 相同。

所以简而言之...

  1. 下载 WIF 和 WIF SDK - http://msdn.microsoft.com/en-us/evalcenter/dd440951.aspx
  2. 下载 StarterSTS - http://startersts.codeplex.com/
  3. 关注 STS 介绍视频 - https://identity.thinktecture.com/download/startersts/v1/StarterSTS_InitialSetup.wmv
  4. 按照 ASP.NET 教程 http://identity.thinktecture.com/download/starterSTS/v1/StarterSTS_FederatingWebApps.wmv
  5. 在 VS 2010 中创建一个新的 MVC 项目
  6. 在项目上右键单击,选择“添加 STS 引用”并按照与 WebForms 应用程序相同的向导步骤进行操作。(将 WIF 信息添加到您的 web.config 文件中。)

现在,当您尝试登录您的 MVC 应用程序时,您将使用 StarterSTS 身份提供程序,它会让您登录..

如果您调试任何控制器方法,您现在将看到您有一个 WIF“ClaimsPrincipal”(它实现了 IPrincipal,因此向后兼容)

需要注意的一件事是,这些教程仅真正涵盖了身份验证。

为了能够从 MVC 应用程序中注销...

添加对 Microsoft.IdentityModel 的引用

(a "known" bug is that it doesn't show up in the VS2010 Add Reference Dialog so you have to reference the dll directly in C:\Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll)

In the templated MVC AccountControllers LogOff method you can now call...

WSFederationAuthenticationModule.FederatedSignOut(null, new Uri("https://RP/"));

where RP is the URI of your own MVC based Relying Party.

Once you have all this set up, using another STS such as ADFS (Active Directory Federation Services) is easy. (as you don't need to do anything other than reconfigure your app to use it.)

As a side note, more screen casts can be found here.

Hope this helps. It's all a bit of a minefield :-)

于 2010-05-10T09:39:23.773 回答
3

有一篇简短的高级文章应该在这里介绍基础知识。

对于真实的示例代码,Microsoft 的Identity Developer Training Kit包含 ASP.NET(以及 Silverlight 等)中的示例。

此外,Microsoft 还发布了一份长篇PDF,名为“基于声明的身份和访问控制的快速指南”,这应该是一个有用的参考资料(第 3 章)。

于 2010-05-11T20:20:12.747 回答
2

一旦您了解了 WIF 如何与 ASP.NET WebForms 一起工作,请查看此处的帖子以在 ASP.NET MVC 中创建自定义授权属性

于 2010-05-11T21:26:35.220 回答
2

MVC + WIF 的一个简单示例可以在上述指南的“与多个合作伙伴联合”一章中找到。直接链接在这里:http: //msdn.microsoft.com/en-us/library/ff359105 (v=PandP.10).aspx

此处记录了其工作原理的基础知识:http: //blogs.msdn.com/b/eugeniop/archive/2010/04/03/wif-and-mvc-how-it-works.aspx

于 2010-05-25T04:03:55.770 回答