Azure Active Directory SSO with Asp.net Webforms(使用ASP.NET WebForms的Azure Active Directory SSO)
问题描述
我们在.NET3.5中有一个ASP.NET WebForms应用程序,它已经有一个带有FormsAuthentication的身份验证模块。对于新的需求,我们需要使用Azure Active Directory实现SSO(SAML)。
我们已按照文章https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/configure-single-sign-on-non-gallery-applications在Azure AD中进行了所需的配置。 下一步是从Azure AD的SAML响应中检索声明值。我们使用Firefox中的SAML Tracer扩展识别SAML响应。 SAML响应屏幕截图如下。
如何使用C#在应用程序的登录页面中解析此响应并提取声明值?
推荐答案
我建议您使用ADFS2.0,它在声明映射方面非常有帮助,并且可以与AD配合使用。
http://msdn.microsoft.com/en-us/magazine/ee335705.aspx
您的应用将在身份验证循环后接收并解析返回到Web服务器的最终声明。
唯一的问题是ADFS只适用于AD,因此如果我们假设所有身份提供者都是基于AD的,那么它将作为IdP工作。对于其他LDAP,您必须寻找其他解决方案。另外,对于SAML响应,它是一个XML输入,您可以像下面这样阅读
XDocument responseDoc = XDocument.Load(@"XMLFile1.xml");
XNamespace pr = "urn:oasis:names:tc:SAML:1.0:protocol";
XNamespace ast = "urn:oasis:names:tc:SAML:1.0:assertion";
XElement status = responseDoc.Element(pr + "Response").Element(pr + "Status");
string statusCode = (string)status.Element(pr + "StatusCode").Attribute("Value");
string statusMessage = (string)status.Element(pr + "StatusMessage");
Console.WriteLine("Status code: {0}; message: {1}.", statusCode, statusMessage);
XElement attStatement = responseDoc.Element(pr + "Response").Element(ast + "Assertion").Element(ast + "AttributeStatement");
string surname = (string)attStatement.Elements(ast + "Attribute").First(a => a.Attribute("AttributeName").Value == "Surname").Element(ast + "AttributeValue");
string firstname = (string)attStatement.Elements(ast + "Attribute").First(a => a.Attribute("AttributeName").Value == "FirstName").Element(ast + "AttributeValue");
string nrn = (string)attStatement.Elements(ast + "Attribute").First(a => a.Attribute("AttributeName").Value == "NRN").Element(ast + "AttributeValue");
Console.WriteLine("First name: {0}, last name: {1}; NRN: {2}", firstname, surname, nrn);
有关详细信息,请查看此帖子
https://forums.asp.net/t/1490469.aspx?parse+SAML+XML+response
希望它能有所帮助。
这篇关于使用ASP.NET WebForms的Azure Active Directory SSO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用ASP.NET WebForms的Azure Active Directory SSO


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01