Pages

Saturday, March 1, 2014

Moving ACS Settings in Cloud Configuration File - Windows Azure Cloud Services

All right folks, This is weekend start and clock is ticking at 5:56AM ,huh.. I am wondering what I am doing by getting up so early this weekend, but anyways.. let me first share this post with you all while I do the thinking in the background..so lets get started..

Well, I wanted to see this issue since long but I didn't get time to investigate more on it, but few days back I had do to it.

What was the issue?

Typically when we want to configure the authentication settings of users of the web application then we use web.config and put all necessary settings there, and so similar is the thing when you want to configure Windows Azure ACS settings in your web application.
Visual Studio provides a great way to do it using nice GUI which is known as Identity and access configuration wizard, you can download it here for Visual Studio 2012 - http://visualstudiogallery.msdn.microsoft.com/e21bf653-dfe1-4d81-b3d3-795cb104066e

Once you are done with configuring all ACS settings in the web.config file and application starts to work fine, you might want to move these settings to cscfg file of your cloud service. Why??
Here is answer to why -
When you put settings in your cscfg files, you can directly go and modify those using Windows Azure management portal without re-deploying the application.
So in this case too, I wanted have more control over ACS settings which were lying in the web.config so far so I was looking for a way to do it.

What is the solution?

Well, there is this excellent post on step by step how you can do it.
Refer it here - http://www.cloudidentity.com/blog/2011/05/31/EDIT-AND-APPLY-NEW-WIF-S-CONFIG-SETTINGS-IN-YOUR-WINDOWS-AZURE-WEBROLE-WITHOUT-REDEPLOYING/

What is basic idea and approach taken here?
Well, if you take a look at the link, the smart approach is taken to override the ACS settings in the WebRole start event using Linq to XML.
Its quite easy to understand - it goes this way
  • Modify your cscfg and csdef to include settings which you want to override
  • Modify WebRole.cs on start method, find the web.config file of your application through code and then modify it using Linq to XML.
and that's it , you are set.

Few points to mention here -
  • Make sure to set the executionContext to elevated
  • Add reference of assembly Microsoft.Web.Administration to your application, you can install nuget Microsoft.Web.Administration
The code which actually modifies the web.config mentioned in the URL might not work for you as it is because you might have added certain customizations while configuring those ACS settings in your web.config file, but not a worry - as a good developer you will be able to tweak it easily.

That's it guys.. Hope you get the idea and if you are also a believer of making things configurable, then I am sure you will find this useful.


No comments:

Post a Comment