AspNetSqlMembershipProvider connection string changing at runtime

L

Larry Neylon

Hi there,

We are in the process of implementing Membership and Role Management and
have a problem with the connection strings in our web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString from the
web.config based upon the domain (so we can handle dev/test/live, etc).

The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
G

Guest

Interesting question! There could be several approaches to this, the simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter
 
D

Dominick Baier

google for "Web Deployment Projects" - a MS add in for VS.

They allow you based on build configuration to change the connection string
section in web.config.


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Interesting question! There could be several approaches to this, the
simplest of which would be to simply have a web.config file containing
the correct element values for the particular deployment scenario, of
course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

Larry Neylon said:
Hi there,

We are in the process of implementing Membership and Role Management
and have a problem with the connection strings in our web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString
from the web.config based upon the domain (so we can handle
dev/test/live, etc).

The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
L

Larry Neylon

Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.


Peter Bromberg said:
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Larry Neylon said:
Hi there,

We are in the process of implementing Membership and Role Management and
have a problem with the connection strings in our web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString from
the
web.config based upon the domain (so we can handle dev/test/live, etc).

The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
S

SAL

While this website acutally is using the wrong name for configuration and imports the wrong library, if you substitute:
Imports System.Configuration
with
Imports System.Web.Configuration

And substitute
ConfigurationMananger
with
WebConfigurationManager

it shows you how to do just what you are talking about:
http://www.ondotnet.com/pub/a/dotnet/2005/02/15/encryptingconnstring.html

HTH

S

Larry Neylon said:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.


Peter Bromberg said:
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Larry Neylon said:
Hi there,

We are in the process of implementing Membership and Role Management and
have a problem with the connection strings in our web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString from
the
web.config based upon the domain (so we can handle dev/test/live, etc).

The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
G

Guest

Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that allow
you to read, modify and save most any kind of configuration data. All you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify the
web.config appropriately, including saving a special key so it doesn't keep
doing it over and over again, and you can get the results you want.

I'd still be more inclined to use an MSBuild or other deployment arrangement
however, rather than attempting to change this kind of stuff on the fly at
runtime.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Larry Neylon said:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I have a
configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and then have
all the other references like AspNetSqlMembershipProvider point to "default"
?

Many thanks,
Larry.


Peter Bromberg said:
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the correct
element values for the particular deployment scenario, of course.

However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and saved at
application startup (say, in Application_Start handler in Global.asax)
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Larry Neylon said:
Hi there,

We are in the process of implementing Membership and Role Management and
have a problem with the connection strings in our web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString from
the
web.config based upon the domain (so we can handle dev/test/live, etc).

The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites / connections
strings
issues than working out the correct one on app startup ?

b) If what we are doing isn't insane, how can you dynamically set the
connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
D

Dominick Baier

In addition - changing the web.config at runtime causes an app domain recycle
and you may loose session or cache data...


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that
allow
you to read, modify and save most any kind of configuration data. All
you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify
the
web.config appropriately, including saving a special key so it doesn't
keep
doing it over and over again, and you can get the results you want.
I'd still be more inclined to use an MSBuild or other deployment
arrangement
however, rather than attempting to change this kind of stuff on the
fly at
runtime.
Peter
Larry Neylon said:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I
have a configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and
then have all the other references like AspNetSqlMembershipProvider
point to "default" ?

Many thanks,
Larry.
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the
correct
element values for the particular deployment scenario, of course.
However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
:

Hi there,

We are in the process of implementing Membership and Role
Management and have a problem with the connection strings in our
web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString
from
the
web.config based upon the domain (so we can handle dev/test/live,
etc).
The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites /
connections
strings
issues than working out the correct one on app startup ?
b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 
G

Guest

Exactly. But if he coded it correctly, it would only happen the one time that
he modifies his web.config, hence the suggestion to have some sort of special
"flag" to prevent it from happening over and over.
Not to be pedantic, but you don't "loose" Session or Cache data. Your pants
may be "loose", which could then cause you to "lose" them. :)
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Dominick Baier said:
In addition - changing the web.config at runtime causes an app domain recycle
and you may loose session or cache data...


-----
Dominick Baier (http://www.leastprivilege.com)

Developing More Secure Microsoft ASP.NET 2.0 Applications (http://www.microsoft.com/mspress/books/9989.asp)
Larry,
Under ASP.NET 2.0, the new ConfigurationManager class has methods that
allow
you to read, modify and save most any kind of configuration data. All
you
would need to do in Application_Start is to get the metadata you need
(hostname, whatever) to determine "what environment" this is, modify
the
web.config appropriately, including saving a special key so it doesn't
keep
doing it over and over again, and you can get the results you want.
I'd still be more inclined to use an MSBuild or other deployment
arrangement
however, rather than attempting to change this kind of stuff on the
fly at
runtime.
Peter
Larry Neylon said:
Thanks for that Peter,

One question, which i can't answer myself as I'm not in the office.

Is the web.config updatable from the Application_Start ? i.e. can I
have a configuration string called "default", which I update in the
Application_Start to the value I need based upon environment, and
then have all the other references like AspNetSqlMembershipProvider
point to "default" ?

Many thanks,
Larry.
in message
Interesting question! There could be several approaches to this, the
simplest
of which would be to simply have a web.config file containing the
correct
element values for the particular deployment scenario, of course.
However, if you look here:

http://msdn2.microsoft.com/en-us/library/ms178411.aspx

you may get some ideas on how this can be dynamically altered and
saved at application startup (say, in Application_Start handler in
Global.asax) Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
:

Hi there,

We are in the process of implementing Membership and Role
Management and have a problem with the connection strings in our
web.config.

We currently have a system that on Application_Start set the
Application["connection_string"] to the relevant ConnectionString
from
the
web.config based upon the domain (so we can handle dev/test/live,
etc).
The problem we have is that we can't see how to dynamically set the
connectionStringName properties in the web.config for
AspNetSqlMembershipProvider, AspNetSqlRoleProvider, etc.

My questions are:

a) Is there a better way to handle the multiple sites /
connections
strings
issues than working out the correct one on app startup ?
b) If what we are doing isn't insane, how can you dynamically set
the connectionStringName for the Membership and Roles stuff ?

Any help or advice would be much appreciated.

Regards,
Larry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top