加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – 如何使用业务标识提供程序(例如ADFS2)

发布时间:2020-12-16 06:48:14 所属栏目:asp.Net 来源:网络整理
导读:我正在运行Win 7,IIS 7.0,VS2012 我创建了asp.mvc4网络应用程序 我在一个单独的VM上安装了ADFS2.0 使用VS 2012中的Identity and Access工具 我选择使用业务标识提供程序(例如ADFS2)并键入STS元数据文档的URL. https://server.local/federationmetadata/2007-
我正在运行Win 7,IIS 7.0,VS2012
我创建了asp.mvc4网络应用程序
我在一个单独的VM上安装了ADFS2.0

使用VS 2012中的Identity and Access工具

我选择使用业务标识提供程序(例如ADFS2)并键入STS元数据文档的URL.

https://server.local/federationmetadata/2007-06/federationmetadata.xml

编辑了Web配置

<system.web>
...
<httpModules>
...
    <remove name="FormsAuthentication" />
</httpModules>
</system.web>

还有这个

<system.webServer>
...
   <modules>
   ...
      <remove name="FormsAuthentication" />
   </modules>
</system.webServer>

还检查了为项目禁用了Windows身份验证

该网站重定向到这样的URL http:// localhost /WebSite/login.aspx?ReturnUrl=/WebSite/,其中包含“无法找到资源”错误.

我还有什么可以帮助你做这项工作?

微软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类似的问题

解决方法

好的,这花了我几天的时间来解决,但这些是我为了让它运行而做的事情.还有很多工作要做.

先决条件:

>在域上运行的ADFS 2.0服务.
> IIS 7,带有自签名证书或可在您的域中使用的证书.
>安装了Identity and Access(版本1.0.2)扩展的Visual Studio 2012.
>一个MVC4 Web应用程序设置为在IIS上运行.
>确保将自签名证书添加到站点,以便您可以通过https访问它.
>您可能必须调整计算机的防火墙设置以允许访问ADFS 2.0服务.

论发展工作站

在你的MVC4项目中

>右键单击Web项目,打开“身份和访问”对话框.
>选择使用业务标识提供程序(例如ADFS2)
>输入STS元数据文档的路径,例如https:// {PATH TO ADFS SERVER} /FederationMetadata/2007-06/FederationMetadata.xml
>输入您的应用领域,例如https:// {WEB APPLICATION URL} /
>尾随斜线有所不同.
>接受这些更改退出对话框.

将以下代码添加到项目中

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服务器上

>如果您使用自签名证书,请导航到您的Web应用程序https:// {WEB APPLICATION URL} /并将区域更改为可信站点.
>在浏览器的地址栏中,您应该能够右键单击证书并安装(您只能从受信任的站点安装证书)证书需要安装在受信任的根权限下 – >注册表,
>打开ADFS控制台,添加信赖方信任,使用联合元数据地址https:// {WEB APPLICATION URL} /FederationMetadata/2007-06/FederationMetadata.xml

添加一些自定义规则

MVC4需要这些规则才能生成可用的ClaimsPrincipal

在Name属性上添加传递规则.

而这两个自定义规则

=> 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");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读