Error al encryptar web config

02/05/2007 - 12:14 por verci | Informe spam
Hola

Estoy tratando de encryptar la sección connection string del web.config en
mi website, pero me aparece este error, gracias de antemano por su ayuda.


Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and modify your configuration file appropriately.

Parser Error Message: The entry 'SiteDB' has already been added.

Source Error:

Line 50: </location>
Line 51: <connectionStrings>
Line 52: <add name="SiteDB" connectionString="Data
Source=Movil1\Movil1;Initial Catalog=Inventory;User ID=sa; Password=xxx"
providerName="System.Data.SqlClient"/>


Source File: C:\Documents and Settings\verci\My Documents\Visual Studio
2005\testsite\web.config Line: 52



Este es el código que uso en mi codebehind page.

Imports System

Imports System.Web.Configuration

Imports System.IO

Imports System.Data

Imports System.Configuration

Imports System.Collections

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls

Partial Class Test101

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

ProtectSection("connectionStrings", "DataProtectionConfigurationProvider")

End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click

UnProtectSection("connectionStrings")

End Sub

Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As
String)

Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)

Dim section As ConfigurationSection = config.GetSection(sectionName)

If Not (section Is Nothing) AndAlso Not
section.SectionInformation.IsProtected Then

section.SectionInformation.ProtectSection(provider)

config.Save()

End If

End Sub

Private Sub UnProtectSection(ByVal sectionName As String)

Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)

Dim section As ConfigurationSection = config.GetSection(sectionName)

If Not (section Is Nothing) AndAlso section.SectionInformation.IsProtected
Then

section.SectionInformation.UnprotectSection()

config.Save()

End If

End Sub



End Class
 

Leer las respuestas

#1 Victor B.
02/05/2007 - 13:00 | Informe spam
Parece que en tu web.config ya tienes otra línea en la que has puesto el
nombre SiteDB. Al menos es lo que interpreto del mensaje de error:
Parser Error Message: The entry 'SiteDB' has already been added.


Víctor B.
Desarrollador independiente

"verci" escribió en el mensaje
news:
Hola

Estoy tratando de encryptar la sección connection string del web.config en
mi website, pero me aparece este error, gracias de antemano por su ayuda.


Description: An error occurred during the processing of a configuration
file required to service this request. Please review the specific error
details below and modify your configuration file appropriately.

Parser Error Message: The entry 'SiteDB' has already been added.

Source Error:

Line 50: </location>
Line 51: <connectionStrings>
Line 52: <add name="SiteDB" connectionString="Data
Source=Movil1\Movil1;Initial Catalog=Inventory;User ID=sa; Password=xxx"
providerName="System.Data.SqlClient"/>


Source File: C:\Documents and Settings\verci\My Documents\Visual Studio
2005\testsite\web.config Line: 52



Este es el código que uso en mi codebehind page.

Imports System

Imports System.Web.Configuration

Imports System.IO

Imports System.Data

Imports System.Configuration

Imports System.Collections

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls

Partial Class Test101

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

ProtectSection("connectionStrings", "DataProtectionConfigurationProvider")

End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click

UnProtectSection("connectionStrings")

End Sub

Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As
String)

Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)

Dim section As ConfigurationSection = config.GetSection(sectionName)

If Not (section Is Nothing) AndAlso Not
section.SectionInformation.IsProtected Then

section.SectionInformation.ProtectSection(provider)

config.Save()

End If

End Sub

Private Sub UnProtectSection(ByVal sectionName As String)

Dim config As Configuration =
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)

Dim section As ConfigurationSection = config.GetSection(sectionName)

If Not (section Is Nothing) AndAlso section.SectionInformation.IsProtected
Then

section.SectionInformation.UnprotectSection()

config.Save()

End If

End Sub



End Class


Preguntas similares