c# - Setting MachineKey via app settings -
we have .net 4.5.x oss application deploying azure websites using git deploy. have build server commits artifacts git repo , use git deploy. use app settings in azure control everything. however, i'm running roadblocks finding way set machine key via app settings / environmental variables. else run issue , solve it?
p.s., seems thing uses machinekey in our app signalr... wonder if there safe , secure way replace iprotectdata without using machine key generate tokens.
like wanted able set machine keys not commit them web.config goes source control , becomes security risk, , able use same per-environment config system use appsettings. did find solution this, though it's bit ugly uses reflection manipulate machinekeysection
configuration.
var getter = typeof(machinekeysection).getmethod("getapplicationconfig", bindingflags.static | bindingflags.nonpublic); var config = (machinekeysection)getter.invoke(null, array.empty<object>()); var readonlyfield = typeof(configurationelement).getfield("_breadonly", bindingflags.instance | bindingflags.nonpublic); readonlyfield.setvalue(config, false); config.decryptionkey = mykeys.encryptionkey; config.validationkey = mykeys.validationkey; readonlyfield.setvalue(config, true);
i wanted able to, if @ possible, extract , use current machine keys on production server, not have forcibly log off our logged in users. ended doing similar this answer, uses reflection.
full solution: https://gist.github.com/cmcnab/d2bbed02eb429098ed3656a0729ee40a
Comments
Post a Comment