2017-06-07 1 views
1

Je reçois l'erreur suivante lorsque je lance mon code:avec web.config et CDATA

System.Configuration.ConfigurationErrorsException: 'La section de configuration ne peut pas contenir un élément CDATA ou texte'

L'application se construit très bien mais quand je sélectionne le lien pour aller à la vue "about" dans l'application, elle renvoie l'erreur ci-dessus.

Ceci est la ligne qu'il met en avant dans le code:

string conn = ConfigurationManager.ConnectionStrings["CountryConnectionString"].ConnectionString; 

et c'est la chaîne de connexion dans le fichier web.config:

<add name="CountryConnectionString" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestData" providerName="System.Data.SqlClient" />  

S'il en faut plus me faire connaître et Je peux poster tout ce que vous avez besoin

Voici l'intégralité du fichier de configuration web

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please  visit 
    https://go.microsoft.com/fwlink/?LinkId=301880 
    --> 
<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <httpModules> 
      <add name="ApplicationInsightsWebTracking"  type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
</httpModules> 
    </system.web> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" culture="neutral"  publicKeyToken="30ad4fe6b2a6aeed" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
    </dependentAssembly> 
</assemblyBinding> 
    </runtime> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules> 
     <remove name="ApplicationInsightsWebTracking" /> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
</modules> 
    </system.webServer> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
</compilers> 
    </system.codedom> 
    <connectionStrings> 
<add name="CountryConnectionString" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestData" providerName="System.Data.SqlClient" />  
    </connectionStrings> 
</configuration> 
+0

Il y a probablement une autre erreur dans votre fichier de configuration. Si c'est le cas, il génère une erreur la première fois qu'il est accédé. BTW: CountryConnectionSrting contient une faute de frappe. – realbart

+0

Ok j'ai corrigé la faute de frappe et il jette toujours l'erreur (je me sentais plutôt idiot de poster une faute de frappe pour commencer) – Max

+0

Pouvez-vous poster plus de votre fichier de configuration? au moins la section complète connectionstrings? – realbart

Répondre

0

Solution courte: supprime tout espace blanc entre les balises.

Si je copie votre config contient un caractère qui se traduit par des espaces, mais ne l'est pas en réalité. Pour l'analyseur de config autre que les espaces et les onglets, est le texte. Le texte n'est pas autorisé dans les fichiers de configuration.

// the spacing character 
Encoding.UTF8.GetBytes(new[] { ' ' })[0] // yields 194 
Encoding.UTF8.GetBytes(new[] { ' ' })[1] // yields 160 

// the actual space 
Encoding.UTF8.GetBytes(new[] { ' ' })[0] // yields 32 

Essayez de changer la config:

<connectionStrings><add name="CountryConnectionString" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestData" providerName="System.Data.SqlClient" /></connectionStrings> 

Avant espaces Réaddition et entre

<connectionStrings> 
    <add name="CountryConnectionString" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestData" providerName="System.Data.SqlClient" /> 
</connectionStrings> 
+0

C'était parfait. Maintenant, juste pour comprendre pourquoi c'était là pour commencer :-) – Max