1

I'm currently working on a windows azure project in C# ( https://github.com/ismaelbelghiti/Tigwi ) and to connect to the storage account I need a connection string with the storage account key, but then the key appears in the source code. How could I avoid the key from appearing in the code source ?

I thought about using a non-commited file in which I would store the confidential information, but i can't find how to use the information on the file from the .cscfg or .csproj files.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Guigui
  • 36
  • 4

2 Answers2

1

No need to store the key in source code. It can be stored in your ServiceConfiguration.cscfg as a connection string, and read in at runtime. This is common practice, as this connection string can change.

Consider that:

  • when running locally for testing, you might want to use the dev storage provided via the emulator. That's a completely different connection string than the one in Windows Azure Storage.
  • Everyone who downloads your project will use a different connection string.

Check out the Windows Azure Platform Training Kit. The very first lab shows, among other things, how to configure a connection string in the configuration file and read it in later. You can also look at this msdn article for the steps needed for adding this connection string, and related code snippet for reading it in.

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • The connection string is already stored in the ServiceConfiguration.Cloud.cscfg file, but that file is uploaded on the public github repository – Guigui Mar 27 '12 at 11:12
  • 1
    Well, just replace the real connection string pieces with and and check that in instead. This now becomes more of a git question and less of a Windows Azure question. – David Makogon Mar 27 '12 at 11:14
0

When you have the project locally you can use UseDevelopmentStorage=true

And for your publishing properties you can have it replaced when deployed to Azure.

Are you saying the key is compiled in the source code?

Adam
  • 16,089
  • 6
  • 66
  • 109
  • To connect to Azure storage, I use a connection string which appears in the ServiceConfiguration.Cloud.cscfg file – Guigui Mar 27 '12 at 11:10
  • Don't upload your Azure project to Git or blank out the configuration before you commit. The Azure project is generally going to be user defined not part of an open source project. – Adam Mar 27 '12 at 13:50