you can not edit the contents of the web.config file dynamically. What you can do is put several different providers in the web.config - even if the only difference is the application name. Then dynamically choose which provider you want dynamically like this:
Membership.Providers["MyOtherProvider"].ValidateUser(username, pwd);
then in web.config
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
maxInvalidPasswordAttempts="3"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="webportal"/>
<add name="MyOtherProvider" ...
...
/>
</providers>
</membership>