我正在尝试开发一个使用包SAML2.dll的应用程序(我用NuGet下载)。要正确配置我的应用程序,我们必须在Web.config文件中添加几个部分:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
**<section name="saml2" type="SAML2.Config.Saml2Section, SAML2" />**
</configSections>
<connectionStrings>...</connectionStrings>
<appSettings>...</appSettings>
<system.web>...</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
**<handlers>
<remove name="SAML2.Protocol.Saml20SignonHandler" />
<remove name="SAML2.Protocol.Saml20LogoutHandler" />
<remove name="SAML2.Protocol.Saml20MetadataHandler" />
<add name="SAML2.Protocol.Saml20SignonHandler" verb="*" path="Login.ashx" type="SAML2.Protocol.Saml20SignonHandler, SAML2" />
<add name="SAML2.Protocol.Saml20LogoutHandler" verb="*" path="Logout.ashx" type="SAML2.Protocol.Saml20LogoutHandler, SAML2" />
<add name="SAML2.Protocol.Saml20MetadataHandler" verb="*" path="Metadata.ashx" type="SAML2.Protocol.Saml20MetadataHandler, SAML2" />
</handlers>**
</system.webServer>
<runtime>...</runtime>
<entityFramework>...</entityFramework>
**<saml2>
<serviceProvider id="urn:issuer" server="http://localhost:3301/">
<endpoints>
<endpoint localpath="Login.ashx" type="signon" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localpath="Logout.ashx" type="logout" redirectUrl="~/HomePage" />
<endpoint localpath="Metadata.ashx" type="metadata" />
</endpoints>
<nameIdFormats allowCreate="true">
<add format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" />
</nameIdFormats>
<authenticationContexts comparison="Exact">
<add context="urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" referenceType="AuthnContextClassRef" />
</authenticationContexts>
</serviceProvider>
<identityProviders metadata="C:\Users\myUser\Desktop\testMetadata\metadata_Kit_net.xml" />
<metadata>
<contacts>
<contact type="Administrative" company="" givenName="" surName="" email="" phone="" />
</contacts>
<requestedAttributes>
<add name="urn:cn" />
</requestedAttributes>
</metadata>
</saml2>**
</configuration>
问题是会话标记没有可识别的标记,我有39条消息(标记内的每个元素一个):
无法找到元素&#39; saml2&#39;的架构信息。 无法找到元素&#39; serviceProvider&#39;的架构信息。 无法找到元素&#39; id&#39;的架构信息。 ...
我查看了我的dll源代码(SAML2.dll),并且它接缝到了所有标签定义(如第一个Web.config部分中所写: ):
using System.Configuration;
namespace SAML2.Config
{
/// <summary>
/// SAML2 Configuration Section.
/// </summary>
public class Saml2Section : ConfigurationSection
{
/// <summary>
/// Gets the section name.
/// </summary>
public static string Name { get { return "saml2"; } }
#region Elements
/// <summary>
/// Gets or sets the actions to perform on successful processing.
/// </summary>
/// <value>The actions.</value>
[ConfigurationProperty("actions")]
public ActionCollection Actions
{
get { return (ActionCollection)base["actions"]; }
set { base["actions"] = value; }
}
/// <summary>
/// Gets or sets the identity providers.
/// </summary>
/// <value>The identity providers.</value>
[ConfigurationProperty("identityProviders")]
public IdentityProviderCollection IdentityProviders
{
get { return (IdentityProviderCollection)base["identityProviders"]; }
set { base["identityProviders"] = value; }
}
/// <summary>
/// Gets or sets the metadata.
/// </summary>
/// <value>The metadata.</value>
[ConfigurationProperty("metadata")]
public MetadataElement Metadata
{
get { return (MetadataElement)base["metadata"]; }
set { base["metadata"] = value; }
}
/// <summary>
/// Gets or sets the service provider.
/// </summary>
/// <value>The service provider.</value>
[ConfigurationProperty("serviceProvider")]
public ServiceProviderElement ServiceProvider
{
get { return (ServiceProviderElement)base["serviceProvider"]; }
set { base["serviceProvider"] = value; }
}
...
当我拨打网址http://localhost:3301/Login.ashx时,我发现错误: {&#34;属性&#39; localpath&#39;未识别。 (c:\ users \ myUser \ documents \ visual studio 2013 \ Projects \ saml20app \ saml20app \ web.config第98行)&#34;} ,它完全指向该行
<endpoint localpath="Login.ashx" type="signon" redirectUrl="~/AuthenticatedHomePage" />
有人可以帮我解决这个错误吗?
先谢谢你的帮助, 马克
答案 0 :(得分:1)
试图让它工作,所以我用ILSpy打开程序集,看看它想要什么:
<endpoint localPath="Login.ashx" type="SignOn" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localPath="Logout.ashx" type="Logout" redirectUrl="~/HomePage" />
<endpoint localPath="Metadata.ashx" type="Metadata" />
在该示例中的web.config type属性使得它不快了。值得庆幸的是,它可以让您知道它所期望的枚举值。
希望得到这个帮助。