views:

47

answers:

3

Is there any way to not use the <machineKey> and instead provide my own key at runtime. Trying to find a way to read the key from say a SQL database or any centralized store and provide it to FormsAuthentication somehow.

+1  A: 

You can put a machineKey section in web.config for your application. Is that what you mean?

Jarrett Meyer
not really, I need to read it from a key store say a database or any kind of store.
Cosmin Onea
+1  A: 

You can hook to the HttpApplication.Authenticate event in your global.asax and do your own authentication module that can use any key that you want. Take a look at Mono's FormsAuthenticationModule for an example on how FormsAuthenticationTicket et al are used to handle the cookie 'lifetime'.

Gonzalo
this is what I already did. but wanted to know if there is any way to reuse the formsauthentication and inject a new key into it.
Cosmin Onea
Not that I know. Same goes for the validation/encryption key of the form.
Gonzalo
I don't see how I can use my own key in the auth module. There is no way I can change where FormsAuthentication class gets the key from. FormsAuthentication provides only Encrypt and Decrypt methods but no SetKey or anything.
Cosmin Onea
Right, however you can use the same code we use in Mono but replacing the code that reads the key from the configuration with your own code to retrieve the key from wherever you want.
Gonzalo
yeah, I thought I could avoid that somehow
Cosmin Onea
A: 

This seems to not be possible. I switched to Windows Identity Foundation.

Cosmin Onea