Programatically change authentication mode at startup of web app?

C

compurhythms

Is there any way to change the authentication mode of a web app during
startup, say in the globl.asax.cs file? (if you are using c# of
course).

I have a situation where in some cases I need to use forms
authentication and sometimes I need windows authentication. They both
work fine stand-alone with static web.config files, but I need to make
the decision programatically based on external factors. Is this
possible?

I've already tried trapping the Application.Start event in
global.asax.cs and mucking with the properties of the
AuthenticationSection and AuthorizationSection objects that are loaded
from web.config, but even though they can be changed at runtime there
seems to be no effect.

Mike
 
D

Dominick Baier

Hi,

ok - thats a strange requirement :))

programmatically changing the config works -

be sure to get a Configuration object

Configuration c = WebConfigurationManager.OpenWebConfguration("~");

then use GetSection to get ahold of the authentication section - it is important
to call Save() on the Configuration object when you are done. Be prepared
that your app will immediately recycle again after a config change.

But maybe you should come up with a scheme that supports both without having
to change web.config....
 
C

compurhythms

Configuration.Save() did the trick. Thanks. There is some noticable
delay as the web app reinitializes but I'm willing to pay that price.

Mike
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top