我运行的是 Win 7、IIS 7.0、VS2012
我已经创建了 asp.mvc4 网络应用程序
我在单独的 VM 上安装了 ADFS2.0
在 VS 2012 中使用身份和访问工具
我选择使用业务身份提供程序(例如 ADFS2)并键入 STS 元数据文档的 URL。
https://server.local/federationmetadata/2007-06/federationmetadata.xml
编辑了网络配置
<system.web>
...
<httpModules>
...
<remove name="FormsAuthentication" />
</httpModules>
</system.web>
和这个
<system.webServer>
...
<modules>
...
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
还检查了该项目是否禁用了 Windows 身份验证
该网站重定向到这样的网址 http://localhost/WebSite/login.aspx?ReturnUrl=%2fWebSite%2f,其中出现“找不到资源”错误。
我还需要摆弄什么才能完成这项工作?
Microsoft doco 轻量级 http://blogs.msdn.com/b/vbertocci/archive/2012/03/15/windows-identity-foundation-tools-for-visual-studio-11-part-iii-connecting-with-a-business-sts-e-g-adfs2.aspx
我已经在本地开发 STS MS Identity and Access Tool MVC 4 上遇到过类似的问题
最佳答案
好的,这花了我几天的时间来解决,但这些是我为让它运行而做的事情。还有很多事情要做。
先决条件:
开发工作站上
在您的 MVC4 项目中
将以下代码添加到您的项目中
using System;
using System.IdentityModel.Services;
namespace NAMESPACE
{
public class FixedWsFederationAuthenticationModule : WSFederationAuthenticationModule
{
public override void RedirectToIdentityProvider(string uniqueId, string returnUrl, bool persist)
{
//This corrects WIF error ID3206 "A SignInResponse message may only redirect within the current web application:"
//First Check if the request url doesn't end with a "/"
if (!returnUrl.EndsWith("/"))
{
//Compare if Request Url +"/" is equal to the Realm, so only root access is corrected
//https://localhost/AppName plus "/" is equal to https://localhost/AppName/
//This is to avoid MVC urls
if (String.Compare(System.Web.HttpContext.Current.Request.Url.AbsoluteUri + "/", base.Realm, StringComparison.InvariantCultureIgnoreCase) == 0)
{
//Add the trailing slash
returnUrl += "/";
}
}
base.RedirectToIdentityProvider(uniqueId, returnUrl, persist);
}
}
}
在 ADFS 2.0 服务器上
添加一些自定义规则
MVC4 需要这些规则来创建一个可用的 ClaimsPrincipal
在 Name 属性上添加传递规则。
而这 2 个自定义规则
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Value = "true");
=> issue(Type = "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", Value = "true");
关于asp.net-mvc-4 - 如何使用商业身份提供者(例如 ADFS2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410658/