为Azure Web Site 添加ADFS验证支持之二 在代码里使用ADFS
下面我们来创建一个MVC 5.0的ASP.Net程序,并且将它部署到Azure Web Site上
通过Visual Studio 2015创建Web Project 在选择ASP.net模板的地方,更改验证方式

在选择验证方式时选择“Work And School Accounts”,在文本框中填入
1.你公司的ADFS的Metadata的地址,这个地址可以找ADFS的管理员要到,通常如以下形式: https://{youradfs.yourcompany.com}/federationmetadata/2007-06/federationmetadata.xml
2.填入你的WEB应用的URI,因为ADFS是双向验证的,这个URI要跟上一步《为Azure Web Site 添加ADFS验证支持之一 设置ADFS的信任关系》里配置的Url一致 
Web Project创建完成了,如果你的ADFS发布到外网的SSL证书是有受信任的根证书颁发的,这时候只需要将WEB Project发布到Azure WEB Site上就搞定,但是很多时候企业的ADFS发布的SSL证书是自己的AD颁发的,Azure WebSite上并不能验证,这时候就需要在你的代码里面修改一下。 打开App_Start/Startup.Auth.cs将默认的代码,下面添加一行BackchannelCertificaeValidator=null

public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions()); app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata,
BackchannelCertificateValidator=null,
});
}
打开Global.asax.cs添加以下代码:

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ServicePointManager.ServerCertificateValidationCallback = delegate
{
return true;
};
}
添加完代码之后就可以将Web Project发布到Azure Web Site上面了。
这时候我们用浏览器打开发布的Web Site地址,它就会自动跳转到ADFS的登录界面

在这里我们就可以用企业里面的AD账号登录我们的Web Site了。

这里有老外的篇Blog写的更加详细一些,英文好的同学可以参考一下:
http://www.tuicool.com/articles/NrMZ7v2
为Azure Web Site 添加ADFS验证支持之二 在代码里使用ADFS的更多相关文章
- 为Azure Web Site 添加ADFS验证支持之一 设置ADFS的信任关系
很多时候企业开发的应用都会通过AD(Active Directory)进行验证用户名密码的,在企业里面统一一个AD来进行账号密码管理也是一个很好的实践.当企业打算将一个应用迁移到Azure的时候,使用 ...
- Microsoft Azure Web Sites应用与实践【2】—— 通过本地IIS 远程管理Microsoft Azure Web Site
Microsoft Azure Web Sites应用与实践 系列: [1]—— 打造你的第一个Microsoft Azure Website [2]—— 通过本地IIS 远程管理Microsoft ...
- Windows Azure Web Site (7) Web Site配置
<Windows Azure Platform 系列文章目录> 在上一章内容中,我们已经部署了Azure WebSite.我们可以在Web Site配置页面进行配置.如下图: 另外,我们还 ...
- Windows Azure Web Site (10) Web Site测试环境
<Windows Azure Platform 系列文章目录> 我们知道,在使用Azure Cloud Service的时候,会有2个不同的环境,称为Production环境和Stagin ...
- Windows Azure Web Site (16) Azure Web Site HTTPS
<Windows Azure Platform 系列文章目录> 我们在使用微软云Azure Web App的时候,会使用微软的二级域名:http://xxx.chinacloudsites ...
- Windows Azure Web Site (17) Azure Web Site 固定公网IP地址
<Windows Azure Platform 系列文章目录> 在之前的文档中,笔者介绍了Azure Web Site是一个多租户的环境,每个部署单元有一个可以通过Internet访问的入 ...
- [New Portal]Windows Azure Web Site (3) 创建Web Site和云端数据库
<Windows Azure Platform 系列文章目录> 在前一章的内容里,我介绍了使用Windows Azure Management Portal创建Web Site.本章,我将 ...
- Azure Web Site 之 利用Azure Web site 发布网站
由于经常混迹于MSDN Azure论坛,少不了和一些外国朋友打交道.有的时候觉得还是有一些东西可以写出来与外国友人们分享下的, 所以就用一个开源项目建了一个英文blog项目. 在发布的时候,首选的就是 ...
- Windows Azure Web Site (6) 使用FTP发布Azure Web Site
<Windows Azure Platform 系列文章目录> 笔者在之前的文章中介绍的都是使用IDE,也就是Visual Studio,将本地的aspx发布到Azure Web Site ...
随机推荐
- 152.[LeetCode] Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- HDU 5391Z ball in Tina Town 数论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc: http://bestcoder.hdu.edu.cn/contests/c ...
- 第8章 Linux磁盘与文件系统管理
认识EXT2文件系统 文件的系统特性 Linux的正规文件系统为Ext2 文件数据除了文件实际内容外,还包括其他属性(文件权限.文件属性). 文件系统将这两部分数据分别存放在不同的块,权限和属性放在i ...
- Solr初步研究
Solr是一个高性能,采用Java5开发,Solr基于Lucene的全文搜索服务器.同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展并对查询性能进行了优化,并且提供 ...
- HDU 2113 Secret Number
http://acm.hdu.edu.cn/showproblem.php?pid=2113 Problem Description 有一天, KIKI 收到一张奇怪的信, 信上要KIKI 计算出给定 ...
- PAT 1085 PAT单位排行 (Microsoft_zzt)
https://pintia.cn/problem-sets/994805260223102976/problems/994805260353126400 每次 PAT 考试结束后,考试中心都会发布一 ...
- fsocket发送post实现异步请求
function triggerRequest($url, $post_data = array(), $cookie = array()){ //可以通过POST或者GET传递一些参数给要触发的脚本 ...
- PHP面向对象之抽象类,抽象方法
抽象类,抽象方法 抽象类: 是一个不能实例化的类: 定义形式: abstract class 类名{} 为什么需要抽象类: 它是为了技术管理而设计! 抽象方法: 是一个只有方法头,没有方法体的方法 ...
- vue h render function & render select with options bug
vue h render function & render select with options bug https://github.com/xgqfrms/vue/issues/41 ...
- linux & zip & tar
linux & zip & tar https://zzk.cnblogs.com/s?w=blog%3Axgqfrms%20zip # zip -r 递归 file_name.zip ...