2011-01-19 19 views
0

在我的web.config文件中,我有拉<identity>串

<identity userName="CTX_DOMAIN\ldapuser" password="ldapPW" /> 

我怎麼能拉後面的代碼我的C#這些userName和密碼字符串?

回答

1

這應該工作:

System.Web.Configuration.IdentitySection identityInfo = (System.Web.Configuration.IdentitySection)ConfigurationManager.GetSection("system.web/identity"); 
    string userName = identityInfo.UserName; 
    string password = identityInfo.Password; 
+0

的確!非常感謝你 :) – 2011-01-20 00:01:40