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.Prov iders["MyMembershipPr ovider"]
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.Membersh ipProvider =
Membership.Prov iders["DefaultMembers hipProvider"].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 7213
Hi Tomasz
You need to make sure all the potential membership providers are listed in
the web.config file, like this:
<membership defaultProvider ="Mydefaultprov ider">
<providers >
<clear/>
<add connectionStrin gName="ASPNETDB ConnectionStrin g1"
name="MyOraclep rovider"
type="System.We b.Security.Orac leMembershipPro vider "/>
<add connectionStrin gName="ASPNETDB ConnectionStrin g2"
name="Mydefault provider" type="System.We b.Security.SqlM embershipProvid er"/>
</providers>
</membership>
Then in your code, reference the one you want to use:
Dim mbr As MembershipProvi der
mbr = Membership.Prov iders.Item("MyO racleprovider")
' mbr.CreateUser( ....
Response.Write( mbr.GetType)
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
"thomas" <to*@tom.comwro te in message
news:nf******** *********@newss vr29.news.prodi gy.net...
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.Prov iders["MyMembershipPr ovider"]
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.Membersh ipProvider =
Membership.Prov iders["DefaultMembers hipProvider"].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**********@n ewsgroups.nospa mwrote in message
news:eq******** *****@TK2MSFTNG P05.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 ="Mydefaultprov ider">
<providers >
<clear/>
<add connectionStrin gName="ASPNETDB ConnectionStrin g1"
name="MyOraclep rovider"
type="System.We b.Security.Orac leMembershipPro vider "/>
<add connectionStrin gName="ASPNETDB ConnectionStrin g2"
name="Mydefault provider"
type="System.We b.Security.SqlM embershipProvid er"/>
</providers>
</membership>
Then in your code, reference the one you want to use:
Dim mbr As MembershipProvi der
mbr = Membership.Prov iders.Item("MyO racleprovider")
' mbr.CreateUser( ....
Response.Write( mbr.GetType)
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
"thomas" <to*@tom.comwro te in message
news:nf******** *********@newss vr29.news.prodi gy.net...
>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.Pro viders["MyMembershipPr ovider"] 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.Members hipProvider = Membership.Pro viders["DefaultMembers hipProvider"].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 MembershipProvi der.
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
SqlMembershipPr ovider, 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 MyMembershipPro vider : SqlMembershipPr ovider
{
public override void Initialize(stri ng name, NameValueCollec tion config)
{
config["connectionStri ngName"] = ConnectionStrin g.Name;
base.Initialize (name, config);
}
}
And for the completeness:
public static string ComputerName {
get {
if (System.Web.Htt pContext.Curren t == null) {
return System.Windows. Forms.SystemInf ormation.Comput erName;
} else {
return System.Web.Http Context.Current .Server.Machine Name;
}
}
}
public static ConnectionStrin gSettings ConnectionStrin g {
get {
ConnectionStrin gSettings connectionStrin g = null;
connectionStrin g = ConfigurationMa nager.Connectio nStrings[ComputerName+
"ConnectionStri ng"];
if (connectionStri ng == null) {
connectionStrin g =
ConfigurationMa nager.Connectio nStrings["DefaultConnect ionString"];
}
return connectionStrin g;
}
}
Now I can define several connection strings in the config
<connectionStri ngssection, each for the host/environment where I plan to
install my application, and one default MembershipProvi der of the
MyMembershipPro vider type with empty connection string. Example:
<connectionStri ngs>
<add name="SomeHost1 ConnectionStrin g" connectionStrin g="..."/>
<add name="SomeHost2 ConnectionStrin g" connectionStrin g="..."/>
<add name="DefaultCo nnectionString" connectionStrin g="..."/>
</connectionStrin gs>
<membership defaultProvider ="DefaultMember shipProvider">
<providers>
<add name="DefaultMe mbershipProvide r" type="MyMembers hipProvider"
connectionStrin gName="" 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 MambershipProvi der 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 above and beyond what the
prodiver currently allows. I need the ability to access a user id and the
user's permission id. With Forms authentication in...
|
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
Administration tool, use the aspnet_regsql command-line utility to
create and configure the database, and then return to this tool to set
the provider....
|
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 app, added 2 users beside the "thardy" user already
shipped with the aplication. I can not pass the Login page, I always get the
following message on...
|
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 new membershipuser in the
CreateUserWizard control.
i think i need to define a custom provider for membership and i tried this:
web.config:
|
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 going to need a cached
solution to avoid the database hits.
(My roles and users seldom/never change after a project rollout)
I wanted to ask in...
| |
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 servers I am attempting to
register another provider instance.
I'm not sure this is the right deployment choice but I haven't found any
guidelines on...
|
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 are all work
well.
Now we have a need to have many different asp.net websites and web services
use a single security database because they all...
|
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 questions come to
mind.
1. How would one implement GetNumberOfUsersOnline? I'm not sure where there
is any indication of this? And it this affected by...
|
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 fail?
Context:
We are using the ActiveDirectory Membership Provider as part of our authentication solution. It is working great most of the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |