{"id":315,"date":"2011-05-31T01:30:00","date_gmt":"2011-05-31T10:30:00","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/2011\/05\/31\/edit-and-apply-new-wifs-config-settings-in-your-windows-azure-webrole-without-redeploying\/"},"modified":"2013-03-14T20:33:31","modified_gmt":"2013-03-15T05:33:31","slug":"edit-and-apply-new-wif-s-config-settings-in-your-windows-azure-webrole-without-redeploying","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2011\/05\/31\/edit-and-apply-new-wif-s-config-settings-in-your-windows-azure-webrole-without-redeploying\/","title":{"rendered":"Edit and Apply New WIF\u2019s Config Settings in Your Windows Azure WebRole\u2026 Without Redeploying!"},"content":{"rendered":"<p>In short: in this post I will show you how you can leverage the OnStart event of a WebRole to enable changing the WIF config settings even after deployment.<\/p>\n<p>Since the very first time <a href=\"http:\/\/dynamic-cast.com\/\">Hervey<\/a> and I made <a href=\"http:\/\/bit.ly\/iwVN6Q\">the first foray<\/a> in Windows Azure with WIF, all the way to the latest <a href=\"http:\/\/msdn.microsoft.com\/en-us\/identitytrainingcourse_identityandazure_unit\">hands-on labs<\/a>, <a href=\"http:\/\/www.amazon.com\/gp\/product\/0735627185?ie=UTF8&amp;tag=wwwcloudident-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735627185\">books<\/a> and <a href=\"http:\/\/bit.ly\/eKDgsf\">whitepapers<\/a>, one of the main challenges of using WIF in a WebRole has always been the impossibility of updating the settings in <font face=\"Courier New\"><strong>&lt;microsoft.identityModel&gt;<\/strong><\/font> without redeploying (or preparing in advance for a pool of alternative <strong><font face=\"Courier New\">&lt;service&gt;<\/font><\/strong> elements fully known at deployment time).<\/p>\n<p>Last Friday I was chatting with <a href=\"http:\/\/www.wadewegner.com\/\">Wade<\/a> about how to solve this very problem for some future deliverables in the <a href=\"http:\/\/watoolkitwp7.codeplex.com\/documentation\">toolkit<\/a>, and it just came to me: why don\u2019t we just leverage the WebRole lifecycle and use <font face=\"Courier New\"><strong>OnStart<\/strong><\/font> for setting the values we want <em>even before WIF reads the web.config<\/em>? All we need to do is create suitable &lt;setting&gt; entries in the ServiceConfiguration.cfg file, which can be modified without the need to redeploy, and use the events in WebRole.cs to ensure that our apps picks up the new values. Simple!<\/p>\n<p>I created a new WebRole, hooked it to a local <a href=\"http:\/\/bit.ly\/b79GSz\">SelfSTS<\/a>, and started playing with <strong>ServiceDefinition.csdef<\/strong>, <strong>ServiceConfiguration.cscfg <\/strong>and <strong>WebRole.cs<\/strong>. I just wanted to make sure the idea works, hence I didn\u2019t pour much care in writing clean (or exhausting) code. Also, I totally ignored all the considerations about HTTPS, NLB session management and all those other things you learned you need to do in WIndows Azure. None of those really interferes with the approach, hence for the sake of simplicity I left them all out.<\/p>\n<p>First, I created &lt;Setting&gt; entries&#160; in the .csdef for every WIF config parameter generated by the Add STS Reference you\u2019d likely want to control:<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\"><span style=\"color: #0000ff\">&lt;?<\/span><span style=\"color: #800000\">xml<\/span> <span style=\"color: #ff0000\">version<\/span><span style=\"color: #0000ff\">=&quot;1.0&quot;<\/span> <span style=\"color: #ff0000\">encoding<\/span><span style=\"color: #0000ff\">=&quot;utf-8&quot;<\/span>?<span style=\"color: #0000ff\">&gt;<\/span><br \/><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">ServiceDefinition<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;WindowsAzureProject5&quot;<\/span> <span style=\"color: #ff0000\">xmlns<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/schemas.microsoft.com\/ServiceHosting\/2008\/10\/ServiceDefinition&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>  <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">WebRole<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;WebRole1&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Runtime<\/span> <span style=\"color: #ff0000\">executionContext<\/span><span style=\"color: #0000ff\">=&quot;elevated&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>    <br \/>    <span style=\"color: #008000\">&lt;!--... stuff--&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">ConfigurationSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;audienceUri&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;issuer&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;realm&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;trustedIssuersThumbprint&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;trustedIssuerName&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">ConfigurationSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>  <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">WebRole<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">ServiceDefinition<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><\/div>\n<p>Yes, yes, having settings just for one issuer in the trusted issuers registry is not especially elegant; and adding a homeRealm would probably be useful. Some other time.<br \/>\n  <br \/>The important thing to notice here is the <strong><font face=\"Courier New\">&lt;Runtime executionContext=elevated\u201d \/&gt;<\/font><\/strong>. Without that, you won\u2019t be able to save the modifications to the Web.Config.<\/p>\n<p>Then I added the same settings in the .cscfg, leaving all the values empty (for now).<\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\"><span style=\"color: #0000ff\">&lt;?<\/span><span style=\"color: #800000\">xml<\/span> <span style=\"color: #ff0000\">version<\/span><span style=\"color: #0000ff\">=&quot;1.0&quot;<\/span> <span style=\"color: #ff0000\">encoding<\/span><span style=\"color: #0000ff\">=&quot;utf-8&quot;<\/span>?<span style=\"color: #0000ff\">&gt;<\/span><br \/><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">ServiceConfiguration<\/span> <span style=\"color: #ff0000\">serviceName<\/span><span style=\"color: #0000ff\">=&quot;WindowsAzureProject5&quot;<\/span> <span style=\"color: #ff0000\">xmlns<\/span><span style=\"color: #0000ff\">=&quot;http:\/\/schemas.microsoft.com\/ServiceHosting\/2008\/10\/ServiceConfiguration&quot;<\/span> <span style=\"color: #ff0000\">osFamily<\/span><span style=\"color: #0000ff\">=&quot;1&quot;<\/span> <span style=\"color: #ff0000\">osVersion<\/span><span style=\"color: #0000ff\">=&quot;*&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>  <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Role<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;WebRole1&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Instances<\/span> <span style=\"color: #ff0000\">count<\/span><span style=\"color: #0000ff\">=&quot;1&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">ConfigurationSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;UseDevelopmentStorage=true&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;audienceUri&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;issuer&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;realm&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;trustedIssuersThumbprint&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/>      <span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">Setting<\/span> <span style=\"color: #ff0000\">name<\/span><span style=\"color: #0000ff\">=&quot;trustedIssuerName&quot;<\/span> <span style=\"color: #ff0000\">value<\/span><span style=\"color: #0000ff\">=&quot;&quot;<\/span> <span style=\"color: #0000ff\">\/&gt;<\/span><br \/><span style=\"color: #008000\">&lt;!--...stuff--&gt;<\/span><br \/>    <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">ConfigurationSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/>    <span style=\"color: #008000\">&lt;!--...stuff--&gt;<\/span><br \/>  <span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">Role<\/span><span style=\"color: #0000ff\">&gt;<\/span><br \/><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">ServiceConfiguration<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<p><\/div>\n<p>Very straightforward. Then I went ahead and added to WebRole.cs&#160; the code below: <\/p>\n<div id=\"codeSnippetWrapper\">\n<pre id=\"codeSnippet\"><span style=\"color: #0000ff\">namespace<\/span> WebRole1<br \/>{<br \/>    <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">class<\/span> WebRole : RoleEntryPoint<br \/>    {<br \/>        <span style=\"color: #0000ff\">public<\/span> <span style=\"color: #0000ff\">override<\/span> <span style=\"color: #0000ff\">bool<\/span> OnStart()<br \/>        {<br \/>            RoleEnvironment.Changing += RoleEnvironmentChanging;<br \/><br \/>                <span style=\"color: #0000ff\">using<\/span> (var server = <span style=\"color: #0000ff\">new<\/span> ServerManager())<br \/>                {<br \/>                    var siteNameFromServiceModel = <span style=\"color: #006080\">&quot;Web&quot;<\/span>;<br \/>                    var siteName =<br \/>                        <span style=\"color: #0000ff\">string<\/span>.Format(<span style=\"color: #006080\">&quot;{0}_{1}&quot;<\/span>, RoleEnvironment.CurrentRoleInstance.Id, siteNameFromServiceModel);<br \/><br \/>                    <span style=\"color: #0000ff\">string<\/span> configFilePath = server.Sites[siteName].Applications[0].VirtualDirectories[0].PhysicalPath + <span style=\"color: #006080\">&quot;\\Web.config&quot;<\/span>;<br \/>                    XElement element = XElement.Load(configFilePath);<br \/><br \/>                    <span style=\"color: #0000ff\">string<\/span> strSetting;<br \/><br \/>                    <span style=\"color: #0000ff\">if<\/span> (!(String.IsNullOrEmpty(strSetting = RoleEnvironment.GetConfigurationSettingValue(<span style=\"color: #006080\">&quot;audienceUri&quot;<\/span>))))<br \/>                        element.Element(<span style=\"color: #006080\">&quot;microsoft.identityModel&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;service&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;audienceUris&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;add&quot;<\/span>).Attribute(<span style=\"color: #006080\">&quot;value&quot;<\/span>).Value = strSetting;<br \/>                    <span style=\"color: #0000ff\">if<\/span> (!(String.IsNullOrEmpty(strSetting = RoleEnvironment.GetConfigurationSettingValue(<span style=\"color: #006080\">&quot;issuer&quot;<\/span>))))<br \/>                        element.Element(<span style=\"color: #006080\">&quot;microsoft.identityModel&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;service&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;federatedAuthentication&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;wsFederation&quot;<\/span>).Attribute(<span style=\"color: #006080\">&quot;issuer&quot;<\/span>).Value = strSetting;<br \/>                    <span style=\"color: #0000ff\">if<\/span> (!(String.IsNullOrEmpty(strSetting = RoleEnvironment.GetConfigurationSettingValue(<span style=\"color: #006080\">&quot;realm&quot;<\/span>))))<br \/>                        element.Element(<span style=\"color: #006080\">&quot;microsoft.identityModel&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;service&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;federatedAuthentication&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;wsFederation&quot;<\/span>).Attribute(<span style=\"color: #006080\">&quot;realm&quot;<\/span>).Value = strSetting;<br \/>                   <br \/>                    <span style=\"color: #0000ff\">if<\/span> (!(String.IsNullOrEmpty(strSetting = RoleEnvironment.GetConfigurationSettingValue(<span style=\"color: #006080\">&quot;trustedIssuersThumbprint&quot;<\/span>))))<br \/>                        element.Element(<span style=\"color: #006080\">&quot;microsoft.identityModel&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;service&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;issuerNameRegistry&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;trustedIssuers&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;add&quot;<\/span>).Attribute(<span style=\"color: #006080\">&quot;thumbprint&quot;<\/span>).Value = strSetting;<br \/>                    <span style=\"color: #0000ff\">if<\/span> (!(String.IsNullOrEmpty(strSetting = RoleEnvironment.GetConfigurationSettingValue(<span style=\"color: #006080\">&quot;trustedIssuerName&quot;<\/span>))))<br \/>                        element.Element(<span style=\"color: #006080\">&quot;microsoft.identityModel&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;service&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;issuerNameRegistry&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;trustedIssuers&quot;<\/span>).Element(<span style=\"color: #006080\">&quot;add&quot;<\/span>).Attribute(<span style=\"color: #006080\">&quot;name&quot;<\/span>).Value = strSetting;<br \/><br \/>                    element.Save(configFilePath);<br \/>                }<br \/>           <br \/>                            <br \/>            <span style=\"color: #0000ff\">return<\/span> <span style=\"color: #0000ff\">base<\/span>.OnStart();<br \/>        }<br \/>        <span style=\"color: #0000ff\">private<\/span> <span style=\"color: #0000ff\">void<\/span> RoleEnvironmentChanging(<span style=\"color: #0000ff\">object<\/span> sender, RoleEnvironmentChangingEventArgs e)<br \/>        {<br \/>            e.Cancel = <span style=\"color: #0000ff\">true<\/span>;<br \/>        }<br \/>    }<br \/>}<\/pre>\n<p><\/div>\n<p>Let\u2019s look at what happens in the using block first. If you want to read good writeups on this technique I suggest <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg494983.aspx\">this msdn entry<\/a> or <a href=\"http:\/\/blog.bareweb.eu\/2011\/05\/azure-howto-programmatically-modify-web-config-on-webrole-startup\/\">this really nice entry from Andy Cross<\/a>.<\/p>\n<p>When OnStart runs, the WebRole application itself didn\u2019t have a chance to do anything yet. What I want to do here is getting my hands on the web.config file, override the WIF settings with all the non-empty values I find in ServiceConfiguration.cscfg and save back the file even before WIF gets to read &lt;microsoft.identityModel&gt;.<\/p>\n<p>What I do above with Linq to XML for modifying the WIF settings is pretty dirty, very brittle and definitely tied to the assumption that the config we\u2019ll be working with is the one that comes out from a typical Add STS Reference run. I tried to use ConfigurationManager at first, but it complained that &lt;microsoft.identityModel&gt; has no schema hence I just went the quicker, easier, more seductive \u201clet\u2019s just see if it works\u201d. But remember, for the one among you who caught the reference: the dark side is not stronger. No no no.<\/p>\n<p>Aaanyway. The <font face=\"Courier New\"><strong>element.Save(configFilePath) <\/strong><\/font>is the line that will fail if you forgot to add the elevated directive in the csdef, you\u2019re warned.<\/p>\n<p>The <strong>RoleEnvironmentChanging<\/strong> handler hookup at the beginning of OnStart, and the handler itself, are meant to ensure that when you change the values in ServiceConfiguration.cscfg Windows Azure will properly restart the role. If you don\u2019t add that, just changing the config will not drive changes in the WebRole behavior until a stop &amp; restart occurs. Technically there are few things you may try to do to get WIF to pick up the new settings at mid flight, but all those would entail changing the application code and that\u2019s exactly what I am trying to avoid with all this brouhaha.<\/p>\n<p>BTW, you can thank <a href=\"http:\/\/www.nickharris.net\/\">Nick Harris<\/a> for the <font face=\"Courier New\"><strong>RoleEnvironment.Changing<\/strong><\/font> trick<img decoding=\"async\" style=\"border-bottom-style: none;border-left-style: none;border-top-style: none;border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/3817.wlEmoticon_2D00_smile_5F00_400ADCAE.png\" \/><\/p>\n<p>Nick just joined the Windows Azure Evangelism team and he is already doing an awesome job.<\/p>\n<p>That should be all. Now, try to ignore the impulse that would make you change the config before deploying, and publish the project in Windows Azure staging \u201cas is\u201d.<\/p>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/3731.image_5F00_0A921A89.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/3731.image_5F00_0A921A89.png\" width=\"404\" height=\"223\" \/><\/a><\/p>\n<p>In few mins the instance is up and running, listening at a nice (and totally unpredictable) URL <a href=\"http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net\">http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net<\/a>. What do you think will happen if I just navigate there?<\/p>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/8524.image_5F00_693274EC.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/8524.image_5F00_693274EC.png\" width=\"400\" height=\"319\" \/><\/a><\/p>\n<p>That\u2019s right. WIF is still configured for the address the application had in the environment formerly known as devfabric (now Windows Azure simulation environment), as described in the realm entry, hence SelfSTS (which behaves like the WIF STS template if there\u2019s no wreply in the signin message) sends the token back there instead of <a href=\"http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net\">http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net<\/a>. Normally we\u2019d be pretty stuck at this point, but thanks to the modification we made we can fix the situation.<\/p>\n<p>All you need to do is navigating to the Windows Azure portal, select the deployment and hit the Configure button.<\/p>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4478.image_5F00_762C54FD.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4478.image_5F00_762C54FD.png\" width=\"400\" height=\"261\" \/><\/a><\/p>\n<p>Here you can pick the Edit current configuration option to update the values inline. In this case, all you need to do is pasting <a href=\"http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net\">http:\/\/eddb883659d04d0bbbb570f17c52ea01.cloudapp.net<\/a> in the audienceUri and realm settings, and hit OK.<\/p>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4885.image_5F00_0326350F.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4885.image_5F00_0326350F.png\" width=\"400\" height=\"316\" \/><\/a><\/p>\n<p>You\u2019ll see the portal updating the instance for few moments. As soon as it reports the role as ready, navigate to its URL and, surprise surprise, this time the authentication flow ends up in the right place! In the screenshot below you can see (thanks to the SecurityTokenVisualizerControl, which you can find in all the latest ACS labs in the <a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=148795\">identity training kit<\/a>) that the audienceURI has been changed as well.<\/p>\n<p><a href=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4403.image_5F00_01E19C30.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/4403.image_5F00_01E19C30.png\" width=\"400\" height=\"359\" \/><\/a><\/p>\n<p>I think that\u2019s pretty cool <img decoding=\"async\" style=\"border-bottom-style: none;border-left-style: none;border-top-style: none;border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/3817.wlEmoticon_2D00_smile_5F00_400ADCAE.png\" \/><\/p>\n<p>Now, you may argue that this scenario is an artifact of how the WIF STS template handles things, and if you would have ben dealing with an STS (like ACS) which keeps realm and return URLs well separated you could have solved the matter at the STS side. All true, but beside the point.<br \/>\n  <br \/>Here I used the staging &amp; realm example because with its unknowable-until-it\u2019s-too-late GUID in the URL it is (was?) the paradigmatic example of what can be challenging when using WIF with Windows Azure; but of course you can use the technique you saw here for pushing out <em>any<\/em> post-deployment changes, including pointing the WebRole to a different STS, updating certificate thumbprints as keys rollover takes place or any other setting you may want to modify.<\/p>\n<p>Please use this technique with caution. I haven\u2019t used extensively yet hence I am not 100% sure if there are gotchas just waiting to be found, but so far it seems to be solving the problem pretty nicely <img decoding=\"async\" style=\"border-bottom-style: none;border-left-style: none;border-top-style: none;border-right-style: none\" class=\"wlEmoticon wlEmoticon-smile\" alt=\"Smile\" src=\"http:\/\/cloudidentity.com\/blog\/wp-content\/uploads\/2011\/05\/3817.wlEmoticon_2D00_smile_5F00_400ADCAE.png\" \/><\/p>\n<div style=\"clear:both\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In short: in this post I will show you how you can leverage the OnStart event of a WebRole to enable changing the WIF config settings even after deployment. Since the very first time Hervey and I made the first foray in Windows Azure with WIF, all the way to the latest hands-on&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[7,8,5,6,4],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-access-control-service","category-acs","category-wif","category-windows-azure","category-windows-identity-foundation"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":1676,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/315\/revisions\/1676"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}