Basically the application I am working on has a bunch of parameters that are all controlled from an xml config file, which contains configurations for each machine that runs the applcation (live and dev). The problem I have is, I want to be able to control the forms based authentication requiressl field, so that in the configuration file, I can specify this flag.
This should cause the requiressl flag to be true in the live environment, and there by enforce ssl and create a secured auth cookie aswell. For the dev environment, I do not wish to enforce ssl on all the dev machines.
I do not want to manipulate the web.config file to do this. I would like my application code to read in the xml configuration and set them accordingl开发者_开发知识库y.
I have tried using reflector to go into the sealed formsauthentication class, and have found that the requiressl property only has a get method, no set method.
I have also tried to implement the formsauthenticationconfiguration class, to no avail. - I am not sure that I am doing this correctly.
Any help in finding a possible solution to this would be greatly appreciated.
Kind regards,
Gurpreet
Attempt 1:
Subsequently I have tried this :
PropertyInfo field = typeof (FormsAuthentication).GetProperty("RequireSSL");
field.SetValue(typeof(FormsAuthentication), true, null)
I get an error message saying "Property set method not found"
Attempt 2: SOLVED
typeof (FormsAuthentication).GetField("_RequireSSL", BindingFlags.Static | BindingFlags.NonPublic).SetValue(typeof(FormsAuthentication), Config.Secure);
Although not recommended, You can use reflection to modify a private field (the backing store for the property).
Try here
精彩评论