开发者

Using keys in same web.config

开发者 https://www.devze.com 2023-01-12 13:24 出处:网络
My application accesses an active directory for login and querying information about users and I\'d like to keep all of my active directory connection information in one place.

My application accesses an active directory for login and querying information about users and I'd like to keep all of my active directory connection information in one place.

I'd like to be able to access AD connection information from web.config. I'd assume the correct way to do that would be through appSettings

<appSettings>
  <add key="LDAPPassword" value="LDAPPassword"/>
  <add key="LDAPPath" value="LDAP://ConnectionString"/>
  <add key="LDAPUser" value="LDAPUser"/>
</appSettings>

How would I go about using these keys further down in the web.config file in order to configure the MembershipProvider?

<membership defaultProvider="ADMembershipProvider">
  <providers>
    <clear />
    <add name="ADMembershipProvider"
         type="System.Web.Security.ActiveDirect开发者_开发技巧oryMembershipProvider, BlahBlahBlah"
         connectionStringName=LDAPPath
         connectionUsername=LDAPUser
         connectionPassword=LDAPPassword
    />
  </providers>
</membership>

If it is not possible to simple use those added keys is there some sort of support for declaring variables elsewhere that will let me keep from repeating this environment specific information? Or is it possible to query the ADMembershipProvider for it's connectionString, connectionUsername and connectionPassword?


You can use Visual Studio Web.config transform to replace placeholders with data using XPath/XSD.

But this doesn't works via Debug - VS doesn't do the transform before debug sessions start and uses "raw" Web.config

In VS2008 you can use pre-build events to launch a custom tool which will replace place-holders with real settings


Are you using .NET 4.0? If so you can make use of the Transform and Locator attributes on the values.

http://msdn.microsoft.com/en-us/library/dd465326.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号