Web.config自定义部分无法识别

时间:2022-03-03 20:21:39

I am trying to develop an application that uses the package SAML2.dll (which I downloaded with NuGet). To properly configure my application, we must add a few sections in the Web.config file:

我正在尝试开发一个使用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>

The issue is that the session tag has no recognized tags, I'm having 39 messages like (one for each element inside the tag):

问题是session标签没有识别的标签,我有39条消息(标签内的每个元素一个):

impossible to find schema information for the element 'saml2'. impossible to find schema information for the element 'serviceProvider'. impossible to find schema information for the element 'id'. ...

无法找到元素'saml2'的架构信息。无法找到元素'serviceProvider'的架构信息。无法找到元素“id”的架构信息。 ...

I looked into my dll's source code (SAML2.dll) and it seams to have all the tags definitions (as written in the first Web.config part: ):

我查看了我的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; }
        }

        ...

When I call the URL http://localhost:3301/Login.ashx, I'm having the error: {"Attribute 'localpath' not recognized. (c:\users\myUser\documents\visual studio 2013\Projects\saml20app\saml20app\web.config line 98)"}, and it points exactly to the line

当我调用URL http:// localhost:3301 / Login.ashx时,我遇到错误:{“属性'localpath'无法识别。(c:\ users \ myUser \ documents \ visual studio 2013 \ Projects \ saml20app \ saml20app \ web.config第98行)}},它指向该行

<endpoint localpath="Login.ashx" type="signon" redirectUrl="~/AuthenticatedHomePage" />

Can someone please help me with this error?

有人可以帮我解决这个错误吗?

Thanks in advance for your help, Marc

先谢谢你的帮助,Marc

1 个解决方案

#1


Got tried of trying to get this to work so I opened the assembly with ILSpy to see what it wanted:

试图让它工作,所以我用ILSpy打开程序集,看看它想要什么:

<endpoint localPath="Login.ashx" type="SignOn" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localPath="Logout.ashx" type="Logout" redirectUrl="~/HomePage" />
<endpoint localPath="Metadata.ashx" type="Metadata" />

The type attribute in the example web.config makes it unhappy too. Thankfully it lets you know the enumerated values it expects.

在本例中的web.config type属性使得它不快也。值得庆幸的是,它让您知道它所期望的枚举值。

Hope this help.

希望这有帮助。

#1


Got tried of trying to get this to work so I opened the assembly with ILSpy to see what it wanted:

试图让它工作,所以我用ILSpy打开程序集,看看它想要什么:

<endpoint localPath="Login.ashx" type="SignOn" redirectUrl="~/AuthenticatedHomePage" />
<endpoint localPath="Logout.ashx" type="Logout" redirectUrl="~/HomePage" />
<endpoint localPath="Metadata.ashx" type="Metadata" />

The type attribute in the example web.config makes it unhappy too. Thankfully it lets you know the enumerated values it expects.

在本例中的web.config type属性使得它不快也。值得庆幸的是,它让您知道它所期望的枚举值。

Hope this help.

希望这有帮助。