Hello All,
How to change the default Membership Provider during the runtime?
I know I can reference any provider I want, e.g.: provider =
Membership.Providers["MyMembershipProvider"]
but the question is how to change the default one, so all those new, cool
controls can start using the one I want.
I can specify the provider for each of those controls, e.g.:
Login1.MembershipProvider =
Membership.Providers["DefaultMembershipProvider"].Name
but it seems like before this line in the Page_Load event handler gets
executes ASP.Net tries to initialize the default one, and since, the
connection string is not always valid, an exception occurs.
I guess, alternatively, I could change the connection string of the default
provider, but I do not know how to.
Any help highly appreciated.
Tomasz 4 7203
Hi Tomasz
You need to make sure all the potential membership providers are listed in
the web.config file, like this:
<membership defaultProvider="Mydefaultprovider">
<providers >
<clear/>
<add connectionStringName="ASPNETDBConnectionString1"
name="MyOracleprovider"
type="System.Web.Security.OracleMembershipProvider "/>
<add connectionStringName="ASPNETDBConnectionString2"
name="Mydefaultprovider" type="System.Web.Security.SqlMembershipProvider"/>
</providers>
</membership>
Then in your code, reference the one you want to use:
Dim mbr As MembershipProvider
mbr = Membership.Providers.Item("MyOracleprovider")
' mbr.CreateUser(....
Response.Write(mbr.GetType)
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
"thomas" <to*@tom.comwrote in message
news:nf*****************@newssvr29.news.prodigy.ne t...
Hello All,
How to change the default Membership Provider during the runtime?
I know I can reference any provider I want, e.g.: provider =
Membership.Providers["MyMembershipProvider"]
but the question is how to change the default one, so all those new, cool
controls can start using the one I want.
I can specify the provider for each of those controls, e.g.:
Login1.MembershipProvider =
Membership.Providers["DefaultMembershipProvider"].Name
but it seems like before this line in the Page_Load event handler gets
executes ASP.Net tries to initialize the default one, and since, the
connection string is not always valid, an exception occurs.
I guess, alternatively, I could change the connection string of the
default provider, but I do not know how to.
Any help highly appreciated.
Tomasz
Hi Ken,
I know that this seems like a typical question many people ask.
That is why I stated in my post that I knew how to reverence an existing
provider knowing that someone may attempt to help without actually reading
the problem description.
But anyway, thank you.
Tomasz
"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:eq*************@TK2MSFTNGP05.phx.gbl...
Hi Tomasz
You need to make sure all the potential membership providers are listed in
the web.config file, like this:
<membership defaultProvider="Mydefaultprovider">
<providers >
<clear/>
<add connectionStringName="ASPNETDBConnectionString1"
name="MyOracleprovider"
type="System.Web.Security.OracleMembershipProvider "/>
<add connectionStringName="ASPNETDBConnectionString2"
name="Mydefaultprovider"
type="System.Web.Security.SqlMembershipProvider"/>
</providers>
</membership>
Then in your code, reference the one you want to use:
Dim mbr As MembershipProvider
mbr = Membership.Providers.Item("MyOracleprovider")
' mbr.CreateUser(....
Response.Write(mbr.GetType)
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
"thomas" <to*@tom.comwrote in message
news:nf*****************@newssvr29.news.prodigy.ne t...
>Hello All,
How to change the default Membership Provider during the runtime?
I know I can reference any provider I want, e.g.: provider = Membership.Providers["MyMembershipProvider"] but the question is how to change the default one, so all those new, cool controls can start using the one I want.
I can specify the provider for each of those controls, e.g.: Login1.MembershipProvider = Membership.Providers["DefaultMembershipProvider"].Name but it seems like before this line in the Page_Load event handler gets executes ASP.Net tries to initialize the default one, and since, the connection string is not always valid, an exception occurs.
I guess, alternatively, I could change the connection string of the default provider, but I do not know how to.
Any help highly appreciated.
Tomasz
Here is the solution I came up with: create own MembershipProvider.
Sounds like a lot of work, doesn't it? Well, actually it does not have to be
created from scratch.
How about altering slightly the behavior of the existing
SqlMembershipProvider, so instead of using the predefined connection string
it grabs the one I specify dynamically, in my case based on the host name?
Here is how simple it is:
class MyMembershipProvider : SqlMembershipProvider
{
public override void Initialize(string name, NameValueCollection config)
{
config["connectionStringName"] = ConnectionString.Name;
base.Initialize(name, config);
}
}
And for the completeness:
public static string ComputerName {
get {
if (System.Web.HttpContext.Current == null) {
return System.Windows.Forms.SystemInformation.ComputerNam e;
} else {
return System.Web.HttpContext.Current.Server.MachineName;
}
}
}
public static ConnectionStringSettings ConnectionString {
get {
ConnectionStringSettings connectionString = null;
connectionString = ConfigurationManager.ConnectionStrings[ComputerName+
"ConnectionString"];
if (connectionString == null) {
connectionString =
ConfigurationManager.ConnectionStrings["DefaultConnectionString"];
}
return connectionString;
}
}
Now I can define several connection strings in the config
<connectionStringssection, each for the host/environment where I plan to
install my application, and one default MembershipProvider of the
MyMembershipProvider type with empty connection string. Example:
<connectionStrings>
<add name="SomeHost1ConnectionString" connectionString="..."/>
<add name="SomeHost2ConnectionString" connectionString="..."/>
<add name="DefaultConnectionString" connectionString="..."/>
</connectionStrings>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="MyMembershipProvider"
connectionStringName="" applicationName="MyApplication"/>
</providers>
</membership>
Now, when the time comes and ASP.Net initializes my customized default
provider the provider will choose the right connection string itself.
The solution can be further extended, but it perfectly works for me as it
is, so I decided to post it here.
Tomasz
One more comment: this method does not actually allows to swap the provider
However, I found that what I, and the most of those who ask this question,
really needed was to be able to make the default MambershipProvider using a
particular connection string, rather than to be able to change the provider
type anytime.
Tomasz This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= |
last post by:
I have been having some trouble with implementing a custom Membership
Provider. We have a custom data store and business logic that pulls user
information. I need some level of functionality...
|
by: Ted |
last post by:
In WSAT, I get the following error when trying to set up my provider:
Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site...
|
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= |
last post by:
Hi, I am trying to play with the Survey manager application provided
gracefully by Microsoft at
"http://msdn.microsoft.com/vstudio/express/sql/samples/" VB team(so many
thanks), compiled the win...
|
by: Ben |
last post by:
Hi,
When an anonymous user has created an new account (with the CreateUserWizard
control), i want to let asp.net generate a password and to send it to the
address of the email provided by the...
|
by: sloan |
last post by:
It looks like the default Membership Provider (and Role Provider) always
goes to the database to get its info.
(GetUsers, GetRoles, etc , etc).
I guess I'm going to roll my own, because I am...
|
by: GaryDean |
last post by:
My ASP.Net application, that uses the SQL Membership Provider, runs fine on
my development box (server2003) as long as I use the standard provider.
But, in anticipation of deployment to other...
|
by: GaryDean |
last post by:
I have serveral applications now running that are using the
MembershipProvider classes and they are each using their own security tables
in SQL Server 2005 instead of the express databases - they...
|
by: Jonathan Wood |
last post by:
Although this will be a challenge at my level of ASP.NET knowledge, I'm
thinking I should implement my own membership provider class.
Looking over the methods I must implement, a number of...
|
by: myth0s |
last post by:
Hi,
The question:
Is it possible to have two differents ActiveDirectory Membership Provider in web.config and change at run-time from the default provider to the second provider if the first one...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |