views:

42

answers:

2

Is there a way i can dynamically populate the username and password of identity in web.config from my code behind... as i cannot hard code it.

<identity impersonate="true" userName = "Admin" password= "xyz">

any help..????

Thanks

This the first part the 2nd part i think i can solve if i get this....

2nd part link text

I got a link which might help me solve the problem but i am having difficulty understanding it and implementing..... link text

any help...

A: 

I think this might help: http://www.velocityreviews.com/forums/t122342-how-to-save-changes-to-a-web-config-section.html

For reference:

public void SaveConfig(Configuration config)
{
    RemotingManager.ShutdownTargetApplication();
    config.NamespaceDeclared = true;

    // check if session expired
    if (String.IsNullOrEmpty(ApplicationPath) ||
     String.IsNullOrEmpty((string)Session[APP_PHYSICAL_PATH]))
    {
     Server.Transfer("~/home2.aspx");
    }

    config.Save(ConfigurationSaveMode.Minimal);
}
Codesleuth
A side effect of modification on web.config is application restart. That's not good most of the times.
Lex Li
I agree - the correct answer for this question would be to save the identity setting elsewhere, and use impersonation in-code (which I see the inquirer has linked: http://support.microsoft.com/kb/306158)
Codesleuth
A: 

That setting is web.config is designed for fixed account impersonation.

If you are really in bad of the flexibility, you may pickup another impersonation option,

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

Lex Li