Page 1 of 1
Change ConnectionString on ASP.NET Membership
Posted: Tue 21 Aug 2012 08:56
by YZahringer
Hello,
I would like to change or create the ConnectionString of OracleMembershipProvider at runtime.
How to do that?
Best regards,
Yann
Re: Change ConnectionString on ASP.NET Membership
Posted: Wed 22 Aug 2012 13:26
by Pinturiccio
You can change or create the ConnectionString of OracleMembershipProvider at runtime. The following example demonstrates it:
web.config:
Code: Select all
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="hi"
providerName="Devart.Data.Oracle" />
</connectionStrings>
...
<membership defaultProvider="Prov">
<providers>
<remove name="Prov" />
<clear/>
<add name="Prov" type="OracleMembershipproviderCS.Prov"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
Default.aspx.cs:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Devart.Data.Oracle.Web.Providers;
using System.Web.Security;
namespace OracleMembershipproviderCS
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Prov.CurrentString = "Your connection string";
Membership.CreateUser("scott2", "tigerSmart_83Proff");
}
}
public class Prov : OracleMembershipProvider
{
public static string CurrentString;
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
base.Initialize(name, config);
base.connectionString = CurrentString;
}
}
}
You should also run the InstallWebTables.sql script against the database you want to use. The script can be found in the \Program Files\Devart\dotConnect\Oracle\ folder.