0

We are currently storing an encryption key in a protected registry key for our other azure apps and have been adding that key via a startup task. While I see that there is a csdef file in the lightswitch app as well, the startup task never seems to fire locally or on azure. I have even tried adding output to the cmd file so I can see if there is any sort of error, but the file is not even created. Lightswitch doesn't seem to have Win32.registry so adding the key via code seems to be out of the question.

Has anyone else been able to get a startup task to run in an azure hosted lightswitch app? As I understand it, the azure side of things shouldn't be that different between lightswitch and projects containing web.worker roles. They are still running on a vm, so a startup task should still be able to access the registry. If it is not possible does anyone have any other ideas on how to add the registry key? Putting the key in the code is definitely not ideal. FYI both the reg file and the cmd file are in the server folder and set to content and copy always.

startup.cmd:

regedit /s 456ddfrt.reg 
exit /b 0

csdef:

 <WebRole name="LightSwitchWebRole"
         vmsize="Small"
         enableNativeCodeExecution="true">
  <Startup>
    <Task commandLine="startup.cmd" executionContext="elevated"  taskType="simple"/>
  </Startup>

Solution

I ended up using Isolated Storage as suggested by Yann. A code example is below.

        //Get key from storage, add if not exists
        try
        {
            String strKey = (string)appSettings["encrKey"];
            strKey = DecryptString(strKey);
        }
        catch (Exception Ex)
        {
            appSettings.Add("encrKey",[mykey]);
            String strKey = (string)appSettings["encrKey"];
            strKey = DecryptString(strKey);
        }

It still involves putting the key in the code, but the key is encrypted using a different encryption method, and on azure the likelihood that they will get access to my code is pretty low. Thanks for all the suggestions!

greg.qds
  • 77
  • 1
  • 6
  • I personally haven't tried this but if you enable RDP on the role, would it help you investigate further? Details here: http://blogs.msdn.com/b/avkashchauhan/archive/2011/08/02/windows-azure-and-visual-studio-lightswitch-2011-part-3-3-adding-rdp-access-to-lightswitch-2011-application-which-is-already-deployed-to-windows-azure.aspx – RichardC Mar 12 '13 at 18:05
  • I don't think rdp would do much in this situation since its not even working on my local machine. I have used before for other things and its been helpful. – greg.qds Mar 13 '13 at 18:03
  • When you go through the publish wizard, are you given the choice of 'Service Type' as 'Web Site' or 'Cloud Service'? I presume you are deploying to a Cloud Service? – RichardC Mar 15 '13 at 09:45

1 Answers1

0

Have you thought about using the application's Application_Initialize method?

Yann Duran
  • 3,842
  • 1
  • 24
  • 24
  • I have, but the problem there is lightswtich doesn't have any of the functions necessary to add the key to the registry. There is no Win32.Registry in lightswitch – greg.qds Mar 13 '13 at 18:01
  • This MSDN forum thread might give you some ideas: http://social.msdn.microsoft.com/Forums/en-US/silverlightnet/thread/a2fd2a83-bac1-41fe-9364-177d3b0a757e/ – Yann Duran Mar 14 '13 at 01:07