ChangePassword.aspx
<form ID="form1" runat="server">
<div>
<asp:TextBox ID="txtUsername" runat="server">
</asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server">
</asp:TextBox>
<asp:Button ID="btnWrite" runat="server" onclick="btnWrite_Click" Text="Modify" />
</div>
</form>
ChangePassword.aspx.cs
protected void btnWrite_Click(object sender, EventArgs e)
{
Configuration webconfig = WebConfigurationManager.OpenWebConfiguration("~");
SystemWebSectionGroup sysweb = (SystemWebSectionGroup)webconfig.GetSectionGroup("system.web");
AuthenticationSection authSection = sysweb.Authentication;
FormsAuthenticationUserCollection users = authSection.Forms.Credentials.Users;
FormsAuthenticationUser user = users[0];
user.Name = txtUsername.Text;
user.Password = txtPassword.Text;
webconfig.Save();
}
Note: Make sure to grant write permissions to web.config file and its parent folders otherwise you will get an exception "
System.InvalidOperationException: ConfigurationSection properties cannot be edited when locked