c# - DotNetOpenAuth 模板在发布时不起作用

标签 c# asp.net iis .net-4.0 iis-7.5

我的 DotNetOpenAuth 模板(样本)在我的本地计算机(作为本地主机)上工作得很好,但是当我将它发布到我的服务器时,我得到了这个错误:

Error Summary
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related 

页面的配置数据无效。

以及详细的错误信息

Module  IIS Web Core
Notification    Unknown
Handler Not yet determined
Error Code  0x800700b7
Config Error    There is a duplicate 'uri' section defined

网络配置:

    <?xml version="1.0"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
    <configSections>
        <section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false"/>
        <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
    </configSections>
    <!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
         which is necessary for OpenID urls with unicode characters in the domain/host name. 
         It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
    <uri>
        <idn enabled="All"/>
        <iriParsing enabled="true"/>
    </uri>
    <system.net>
        <defaultProxy enabled="true"/>
        <settings>
            <!-- This setting causes .NET to check certificate revocation lists (CRL) 
                 before trusting HTTPS certificates.  But this setting tends to not 
                 be allowed in shared hosting environments. -->
            <servicePointManager checkCertificateRevocationList="true"/>
        </settings>
    </system.net>
    <!-- this is an optional configuration section where aspects of dotnetopenauth can be customized -->
    <dotNetOpenAuth>
        <messaging>
            <untrustedWebRequest>
                <whitelistHosts>
                    <!--<add name="localhost" />-->
                </whitelistHosts>
            </untrustedWebRequest>
        </messaging>
        <openid>
            <relyingParty>
                <behaviors>
                    <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
                         with OPs that use Attribute Exchange (in various formats). -->
                    <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth"/>
                </behaviors>
                <store type="RelyingPartyLogic.RelyingPartyApplicationDbStore, RelyingPartyLogic"/>
            </relyingParty>
        </openid>
        <oauth>
            <serviceProvider>
                <store type="RelyingPartyLogic.NonceDbStore, RelyingPartyLogic"/>
            </serviceProvider>
        </oauth>
        <!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
        <reporting enabled="true"/>
    </dotNetOpenAuth>
    <!-- log4net is a 3rd party (free) logger library that DotNetOpenAuth will use if present but does not require. -->
    <log4net>
        <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
            <bufferSize value="100"/>
            <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            <commandText value="INSERT INTO [Log] ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)"/>
            <parameter>
                <parameterName value="@log_date"/>
                <dbType value="DateTime"/>
                <layout type="log4net.Layout.RawTimeStampLayout"/>
            </parameter>
            <parameter>
                <parameterName value="@thread"/>
                <dbType value="String"/>
                <size value="255"/>
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%thread"/>
                </layout>
            </parameter>
            <parameter>
                <parameterName value="@log_level"/>
                <dbType value="String"/>
                <size value="50"/>
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%level"/>
                </layout>
            </parameter>
            <parameter>
                <parameterName value="@logger"/>
                <dbType value="String"/>
                <size value="255"/>
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%logger"/>
                </layout>
            </parameter>
            <parameter>
                <parameterName value="@message"/>
                <dbType value="String"/>
                <size value="4000"/>
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern value="%message"/>
                </layout>
            </parameter>
            <parameter>
                <parameterName value="@exception"/>
                <dbType value="String"/>
                <size value="2000"/>
                <layout type="log4net.Layout.ExceptionLayout"/>
            </parameter>
        </appender>
        <!-- Setup the root category, add the appenders and set the default level -->
        <root>
            <level value="WARN"/>
            <appender-ref ref="AdoNetAppender"/>
        </root>
        <!-- Specify the level for some specific categories -->
        <logger name="DotNetOpenAuth">
            <level value="WARN"/>
        </logger>
        <logger name="DotNetOpenAuth.OpenId">
            <level value="INFO"/>
        </logger>
        <logger name="DotNetOpenAuth.OAuth">
            <level value="INFO"/>
        </logger>
    </log4net>
    <appSettings/>
    <connectionStrings>
        <!-- Remember to keep this connection string in sync with the one (if any) that appears in the log4net section. -->
        <add name="DatabaseEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Pubba_V05.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
    </connectionStrings>
    <system.web>
        <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <remove assembly="DotNetOpenAuth.Contracts"/>
                <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Forms">
            <forms loginUrl="~/login.aspx" name="Pubba_V05"/>
        </authentication>
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.
            -->
        <customErrors mode="RemoteOnly"/>
        <httpModules>
            <add name="OAuthAuthenticationModule" type="RelyingPartyLogic.OAuthAuthenticationModule, RelyingPartyLogic"/>
            <add name="Database" type="RelyingPartyLogic.Database, RelyingPartyLogic"/>
        </httpModules>
        <roleManager enabled="true" defaultProvider="Database">
            <providers>
                <add name="Database" type="RelyingPartyLogic.DataRoleProvider, RelyingPartyLogic"/>
            </providers>
        </roleManager>
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
    <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
        <modules>
            <add name="OAuthAuthenticationModule" type="RelyingPartyLogic.OAuthAuthenticationModule, RelyingPartyLogic"/>
            <add name="Database" type="RelyingPartyLogic.Database, RelyingPartyLogic"/>
        </modules>
    </system.webServer>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="DataApiBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                    <serviceAuthorization serviceAuthorizationManagerType="OAuthAuthorizationManager, __code" principalPermissionMode="Custom"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <!--<service behaviorConfiguration="DataApiBehavior" name="DataApi">
            </service>-->
        </services>
    </system.serviceModel>
    <location path="default.aspx">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>
</configuration>

我该如何解决这个问题?

最佳答案

问题出在这里:

<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

通过删除该行,错误得以解决。

升级到 .NET 4.0 后出现此问题,将大量配置移至 machine.config。

关于c# - DotNetOpenAuth 模板在发布时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4208313/

相关文章:

javascript - 序列化表单发布到 Controller

asp.net - 为什么不是所有具有 Text 属性的 System.Web.UI.WebControl 类都实现 ITextControl?

c# - 如何在 VS 2015 中自定义 ASP.NET MVC 5 脚手架?

powershell - IIS PowerShell应用程序池设置为 'NetworkService'帐户

redirect - 强制 HTTP 到 HTTPS 重定向

c# - 可枚举给出意外输出

c# - Paypal 定期付款 - Express Checkout APPID 被拒绝

c# - 如何在 ExceptionFilterAttribute 中返回自定义信息?

java - 如何从java调用asp.net函数

c# - 页面可以选择退出 IIS 7 压缩吗?