Hello,
I would like to change or create the ConnectionString of OracleMembershipProvider at runtime.
How to do that?
Best regards,
Yann
Change ConnectionString on ASP.NET Membership
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Change ConnectionString on ASP.NET Membership
You can change or create the ConnectionString of OracleMembershipProvider at runtime. The following example demonstrates it:
web.config:
Default.aspx.cs:
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.
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>
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;
}
}
}