Let us consider the following web.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
</connectionStrings>
<system.web>
<pages theme="PetShop" styleSheetTheme="PetShop" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add tagPrefix="blt" namespace="BLToolkit.Web.UI" assembly="BLToolkit.4" />
</controls>
</pages>
<!--
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>
<add assembly="System.Data.Linq, 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 name="PetShopAuth" loginUrl="SignIn.aspx" protection="None" timeout="60" />
</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 defaultRedirect="Error.aspx" mode="RemoteOnly" />
<sessionState mode="Off" />
<anonymousIdentification enabled="true" />
<profile automaticSaveEnabled="false" defaultProvider="ShoppingCartProvider">
<providers>
<add name="ShoppingCartProvider" connectionStringName="ProfileDB" type="PetShop.BusinessLogic.ProfileProvider" applicationName=".NET Pet Shop 4.0" />
<add name="WishListProvider" connectionStringName="ProfileDB" type="PetShop.BusinessLogic.ProfileProvider" applicationName=".NET Pet Shop 4.0" />
<add name="AccountInfoProvider" connectionStringName="ProfileDB" type="PetShop.BusinessLogic.ProfileProvider" applicationName=".NET Pet Shop 4.0" />
</providers>
<properties>
<add name="ShoppingCart" type="PetShop.BusinessLogic.Cart" allowAnonymous="true" provider="ShoppingCartProvider" />
<add name="WishList" type="PetShop.BusinessLogic.Cart" allowAnonymous="true" provider="WishListProvider" />
<add name="AccountInfo" type="PetShop.ObjectModel.Address" allowAnonymous="false" provider="AccountInfoProvider" />
</properties>
</profile>
<!-- Membership Provider for SqlServer -->
<membership defaultProvider="SQLMembershipProvider">
<providers>
<add name="SQLMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MembershipDB" applicationName=".NET Pet Shop 4.0" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" />
</providers>
</membership>
<caching>
<sqlCacheDependency enabled="true" pollTime="10000">
<databases>
<add name="MSPetShop4" connectionStringName="SQLConnString1" pollTime="10000" />
</databases>
</sqlCacheDependency>
</caching>
</system.web>
<location path="UserProfile.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="CheckOut.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
by reading the above config file i need to change the attribute value of type field in membership providers nodes.
type="System.Web.Security.SqlMembershipProvider"
to new value
type="sample.SqlMembershipProvider"
through c#.net lambda expressions
waiting for your responses
I done the solution as
var xDoc = XDocument.Load(inputPathToConfigFile);
var ns = xDoc.Descendants().First(x => x.Name.LocalName == "configuration").Name.Namespace;
var prop = xDoc.Descendants(ns + "membership")
.First(p => p.Attribute("defaultProvider").Value == "SQLMembershipProvider");
if(prop.HasAttributes)
{
var prop1 = prop.Descendants(ns + "add").First(p => p.Attribute("type").Value == "System.Web.Security.SqlMembershipProvider");
prop1.Attribute("type").Value = "sample.membershipprovider";
xDoc.Save(inputPathToConfigFile);
}
Just for your references...