Register custom culture in Windows Azure

2020-07-17 05:50发布

问题:

I am currently developing an ASP.NET MVC 4 app for the African market and was hoping to register a custom culture using the steps detailed in the following link http://msdn.microsoft.com/en-gb/library/system.globalization.cultureandregioninfobuilder.register(v=vs.110).aspx. Most of my target countries are not in the pre-installed cultures so it sounds like I need to register these cultures. Problem is, my console app for doing the registration will need admin previlidges to complete the culture registration. I am presuming windows azure does not allow developers admin control of the cloud service environment.

Question: What is the best way to register a custom culture in Windows Azure without admin previlidges. Apparently there's a way to do this on Framework 2.0 using the cultureandregioninfobuilder.compile method but this is not a supported method. Is there a better solution? Don't want to have to maintain different project solutions for each culture just so I can support different languages.

Thanks in advance.

回答1:

You could create a startup task that runs with elevated priviledges, and also run your application on a limited context. Your service configuration file should look like this:

 <ServiceDefinition name="MyCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-10.1.8">
  <WebRole name="MyWebRole" vmsize="Small">
    <Runtime executionContext="limited">
    </Runtime>
    <Startup>
      <Task executionContext="elevated" commandLine="scripts\SetupCulture.cmd" taskType="simple">
        <Environment>
          <Variable name="CULTURE">
            <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='Culture']/@value" />
          </Variable>
        </Environment>
      </Task>
    </Startup>
    ...

   </WebRole>
 </ServiceDefinition>

Note with this you can specify the desired culture in the service configuration file. Finally you can use the environment variable "CULTURE" in your .cmd file to use it as parameter to a .NET executable doing the job.