<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Ganesh Shankaran's blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:09:35 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Security: Test automation From Build and Release pipe  using Secrets in Key vault</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/security-test-automation-from-build-and-release-pipe-using-secrets-in-key-vault</link>
      <pubDate>Fri, 26 Jan 2018 23:51:33 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/?p=205</guid>
      <description><![CDATA[We follow security guideline at various stages of our application development. Here in this short...]]></description>
      <content:encoded><![CDATA[We follow security guideline at various stages of our application development. Here in this short article I’m going to throw some light with respect to our VSTS build/Release pipe where we can easily secure user credentials that we use to run Test cases, Load test etc., by using Key vault.

<a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application">Key vault</a> has been in use for long and its uses are pretty much known to all of us. While accessing it from a web API it’s obvious that we secure the process of connecting to key vault. A detailed explanation of how to do this has been already included in this <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application">MSDN article</a>. Again, the MSI takes this to a next level where don’t even have to bother storing the certificates. You can read all of that <a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-managed-service-identity">here</a>.

Coming to what this article is about, when we have our CI/CD pipe configured, it is important for us to have access to credentials for a lot of things. for example, run integrated test. When we think of this from security stand point, given we do not have access to our certificates on the build or the test agents it becomes necessary for us to have a way to key vault (to access the secrets in it) without storing secrets or key in the deployment scripts. This is easily possible by using <a href="https://docs.microsoft.com/en-us/vsts/build-release/tasks/deploy/azure-key-vault">Azure key vault task</a>

With service principal we can configures <a href="https://docs.microsoft.com/en-us/vsts/build-release/concepts/library/variable-groups">variable group</a> and fetch it at the run time directly from the key vault in our build and release definitions.

As mentioned <a href="https://docs.microsoft.com/en-us/vsts/build-release/tasks/deploy/azure-key-vault">here</a>, I’m adding the Pre-requisites again in this article for simplicity

The task has the following pre-requisites:
<ul>
 	<li>An Azure subscription linked to Team Foundation Server or VSTS using the <a href="https://docs.microsoft.com/en-us/vsts/build-release/concepts/library/service-endpoints#sep-azure-rm">Azure Resource Manager service endpoint</a>.</li>
 	<li>An <a href="https://azure.microsoft.com/en-us/services/key-vault/">Azure Key Vault </a>containing the secrets.</li>
</ul>
You can create a key vault:
<ul>
 	<li>In the <a href="https://ms.portal.azure.com/#create/Microsoft.KeyVault">Azure portal</a></li>
 	<li>By using <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-get-started#a-idvaultacreate-a-key-vault">Azure PowerShell</a></li>
 	<li>By using the <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-manage-with-cli2#create-a-key-vault">Azure CLI</a></li>
</ul>
Once we have the above pre-requisites, below are few more steps that will help you access the secrets from our definitions.
<ol>
 	<li>Add Azure key vault task and point it to the service principal created along with the key vault that you want to use. A Secrets filter value of ‘*’ will pull the secrets.</li>
</ol>
<img src="https://msdnshared.blob.core.windows.net/media/2018/01/126.png" alt="" width="622" height="333" class="alignnone size-full wp-image-215" />
<ol start="2">
 	<li>For us to able to access the secrets we need to configure variable group that’s our next step. Browse to Library-&gt; VariableGroup</li>
</ol>
<a href="https://msdnshared.blob.core.windows.net/media/2018/01/1110.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/1110.png" alt="" width="1686" height="156" class="alignnone size-full wp-image-265" /></a>

3. As shown below specify your service endpoint, and select your key value from the drop-down list

&nbsp;

<img src="https://msdnshared.blob.core.windows.net/media/2018/01/220.png" alt="" width="800" height="649" class="alignnone size-full wp-image-225" />

4. Its important to authorize the selected key vault so that its accessible from the build/release definition.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/411.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/411.png" alt="" width="800" height="562" class="alignnone size-full wp-image-245" /></a>

&nbsp;
<ol start="5">
 	<li>Now you can select all the secrets that you want to access from the build definition by adding them as shown below.</li>
</ol>
&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/510.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/510.png" alt="" width="1201" height="848" class="alignnone size-full wp-image-255" /></a>

&nbsp;
<ol start="6">
 	<li>Finally, you can access them in your definitions as parameter. For example, you want to access the DatabaseConnection that’s part of your key vault, you can specify them as $(DatabaseConnection).</li>
</ol>
&nbsp;

Now, that’s you get rid of secrets and certificate dependency from your build and release pipeline.

Happy coding!

Ganesh Shankaran]]></content:encoded>
    </item>
    <item>
      <title>Serverless computing with Azure Function in a DevOps Model</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/serverless-computing-with-azure-function-in-a-devops-model</link>
      <pubDate>Wed, 05 Jul 2017 22:33:33 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/?p=55</guid>
      <description><![CDATA[In a DevOps Model, one of the crucial aspect for Engineers is to manage Infrastructure. No matter...]]></description>
      <content:encoded><![CDATA[In a DevOps Model, one of the crucial aspect for Engineers is to manage Infrastructure. No matter how much ever we automate this task becomes cumbersome especially when we have multiple servers involved. While Azure ARM templates helps us spin up an environment on the fly we still have the need to maintain and support the servers. To overcome this hurdle, the direction we are moving towards is to go “Serverless”, that is the cloud provider dynamically manages the allocation of machine resources, and bills based on the actual amount of resources consumed by an application, rather than billing based on pre-purchased units of capacity. This will reduce the cost incurred by an application utilizing the compute resource. In a nutshell, we are not going to pay for scale or for the capacity of resources, but just for the compute (how many times we run and how long we run). And Of course, we don’t have to think about managing these servers.
In this post, I’m going to talk about how we can build a solution using Azure Function (latest version with VS2017 15.3) in DevOps fashion to run small discrete piece of software in the cloud.

For those who have been using Azure Functions that was released with VS2015, might have noticed that the model has completely changed although the fundamentals are the same. Please visit Part1 and Part2 channel 9 video in which Jeff Hollan explains all in depth. The version that was released with VS2015 has been discontinued as the future focus is on pre-compiled functions with the intent to have .NET Standard 2.0, there are dependencies that will only exist in Visual Studio 2017 Update 3 and beyond.
Let’s dive in to the flow to see how can we Create, build and deploy Azure Functions.

<a href="https://blogs.msdn.microsoft.com/webdev/2017/05/10/azure-function-tools-for-visual-studio-2017/">Prerequisites</a>
<ul>
 	<li><span>Install </span><a href="https://blogs.msdn.microsoft.com/visualstudio/2017/08/14/visual-studio-2017-version-15-3-released/">Visual Studio 2017 15.3</a><span> (or later)</span></li>
</ul>
<ul>
 	<li>You must have either the “ASP.NET and web development” or “Azure development” workload installed.</li>
</ul>
<strong><u>Create </u></strong>

Creation of Azure function in Visual studio is as easy as just selecting the project template. Then, it a matter of what logic you need which you can create by adding a Function from the available option.

Right-click on the project to add a new function which will then walk you through the selection wizard.

Cloud -&gt; Azure Functions

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/1.png"><img width="933" height="647" class="alignnone size-full wp-image-115" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/1.png" /></a>

&nbsp;

In the Solution explorer, you will see that now we have an easy option to add dependent libraries from nuget.org or any nuget store. And yes, now its builds in to a class library. This might be new to people who worked with Azure Functions in VS2015

[caption id="attachment_125" align="alignnone" width="522"]<a href="https://msdnshared.blob.core.windows.net/media/2017/07/2.png"><img width="522" height="324" class="wp-image-125 size-full" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/2.png" /></a> Azure Function (VS2017) changes[/caption]

&nbsp;

There is a list of operations that you can do when you create a new Azure function please ref this MSDN <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings">article</a> for details for Azure triggers and bindings.. each of which is explained in detail.

I want to spend a minute looking at the folder structure created when we build the solution.

Inside the folder ..\ganesh\..\ServerlessComputingSample\ServerlessComputingSample\<strong>bin</strong>\<strong>Debug</strong>\<strong>net461</strong> you will see the following

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/3.png"><img width="629" height="119" class="alignnone size-full wp-image-135" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/3.png" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/4.png"><img width="623" height="51" class="alignnone size-full wp-image-145" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/4.png" /></a>

And inside HttpTriggerCharp (the sample function that I added) we will see <strong>function.json</strong>

So, <strong>unlike VS2015 template function.json is now part of build output than being part of the solution</strong>.

Here is the content of it,

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/5.png"><img width="519" height="358" class="alignnone size-full wp-image-155" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/5.png" /></a>

As you would have noticed function.json includes the details on bindings and the library location.

<strong>Note: </strong>

<strong><em>Connecting to On-prem SQL server from Azure Functions</em></strong><em> is possible and it is identical to how we do it for APP services. The only thing we should change is that during creation of Azure Functions we should use _App Service Plan_ instead of Consumption plan. Once we select App service plan, we can click on All settings and create a hybrid connection and follow through to connect to on-premise SQL server. To know the difference between Consumption and App service plan please refer this <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale">article</a>. </em>

&nbsp;

<strong><u>Build</u></strong><u> and <strong>Release</strong> Tasks in VSO</u>

Simple set of Build task include the following where we build the solution and copy the artifacts. Including MSBuild Arguments for the sake of clarity to package the solution.

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/6.png"><img width="924" height="432" class="alignnone size-full wp-image-156" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/6.png" /></a>

Since Azure Functions builds as a DLL there is small change I have done to my solution structure. Although Azure function builds as a DLL , it follow App service path for deployment. As such, for deployment automation, <strong>I have added another empty App service project to my solution, with a Folder named Library and made that as the output path for Function project</strong>. Added the reference to the function DLL from the newly generated DLL in the Library folder. We use this project during our Deployment to simply deploy App service which in-turn deploys our function App.

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/7.png"><img width="335" height="480" class="alignnone size-full wp-image-165" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/7.png" /></a>

<span style="color: #000000;font-family: Calibri">Coming to the release definition we will see the following tasks(you can have additional tasks based on your project requirement) ,</span>

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/22.png"><img width="634" height="438" class="alignnone size-full wp-image-186" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/22.png" /></a>

The first task is for Resource Deployment. In the beginning I had mentioned about Deployment of Resources through Resource template, this is where we do that for our function app. There are many resource template available in <a href="https://azure.microsoft.com/en-us/resources/templates/">Azure Quick Start Template </a> that you can use in your Resource group project for deployment.

For automation Resource group creation I have added an empty <a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/vs-azure-tools-resource-groups-deployment-projects-create-deploy">Azure Resource Group</a> project and modified it

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/33.png"><img width="308" height="131" class="alignnone size-full wp-image-195" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/07/33.png" /></a>

Here is the sample Template detail that needs to be placed in azuredeploy.json
<pre>{
   "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
   "contentVersion": "1.0.0.0",
   "parameters": {
       "appName": {
           "type": "string",
           "metadata": {
               "description": "The name of the function app that you wish to create."
           }
       },
       "sku": {
           "type": "string",
           "allowedValues": [
               "Free",
               "Shared",
               "Basic",
               "Standard"
            ],
           "defaultValue": "Standard",
           "metadata": {
               "description": "The pricing tier for the hosting plan."
           }
       },

       "workerSize": {
           "type": "string",
           "allowedValues": [
               "0",
               "1",
               "2"
           ],
           "defaultValue": "0",
           "metadata": {
               "description": "The instance size of the hosting plan (small, medium, or large)."
           }
       },

       "storageAccountType": {
           "type": "string",
           "defaultValue": "Standard_LRS",
           "allowedValues": [
               "Standard_LRS",
               "Standard_GRS",
               "Standard_ZRS",
               "Premium_LRS"
           ],
           "metadata": {
               "description": "Storage Account type"
           }
       }
   },

   "variables": {
       "functionAppName": "[parameters('appName')]",
       "hostingPlanName": "[parameters('appName')]",
       "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'functions')]"
   },

   "resources": [
       {
           "type": "Microsoft.Storage/storageAccounts",
           "name": "[variables('storageAccountName')]",
           "apiVersion": "2015-06-15",
           "location": "[resourceGroup().location]",
           "properties": {
               "accountType": "[parameters('storageAccountType')]"
           }
       },
       {
           "type": "Microsoft.Web/serverfarms",
           "apiVersion": "2015-04-01",
           "name": "[variables('hostingPlanName')]",
           "location": "[resourceGroup().location]",
           "properties": {
               "name": "[variables('hostingPlanName')]",
               "sku": "[parameters('sku')]",
               "workerSize": "[parameters('workerSize')]",
               "hostingEnvironment": "",
               "numberOfWorkers": 1
           }
       },
       {
           "apiVersion": "2015-04-01",
           "type": "Microsoft.Web/sites",
           "name": "[variables('functionAppName')]",
           "location": "[resourceGroup().location]",
           "kind": "functionapp",
           "properties": {
               "name": "[variables('functionAppName')]",
               "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
               "hostingEnvironment": "",
                     "clientAffinityEnabled": false,
                     "alwaysOn": true
          },
           "dependsOn": [
               "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
               "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
           ],
           "resources": [

               {
                   "apiVersion": "2016-03-01",
                   "name": "appsettings",
                   "type": "config",
                   "dependsOn": [
                       "[resourceId('Microsoft.Web/sites', variables('functionAppName'))]",
                       "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
                   ],

                   "properties": {

                       "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",

                       "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",

                       "FUNCTIONS_EXTENSION_VERSION": "~1"
                   }
               }
                     ]
       }
   ]
}</pre>
&nbsp;

Wanted to point out that you will need <strong>service principle</strong> for this task which you create by following the details in this <a href="https://docs.microsoft.com/en-us/azure/vs-azure-tools-resource-groups-ci-in-vsts">article</a>.

<strong>Azure App service task deployment</strong> is where we will deploy our App Service Deployment project that we created earlier. I won’t go in to details as this is straight forward.

<strong>Configuration</strong> setup is done through PowerShell script. Here is the PowerShell Script that you can use to set up Azure Function app settings, you can run this from a script task for deployment automation.
<pre>Param(
[string]$myResourceGroup,
[string]$mySite)
$webApp = Get-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -Slot production
$appSettingList = $webApp.SiteConfig.AppSettings
$setting = @{}
ForEach ($kvp in $appSettingList) {
$setting[$kvp.Name] = $kvp.Value
}
$setting['settingName1'] = &lt;"Settingvalue1"&gt;
$setting['settingName2'] = &lt;"Settingvalue2"&gt;
$setting['settingName3'] = &lt;"Settingvalue3"&gt;
Set-AzureRMWebAppSlot -ResourceGroupName $myResourceGroup -Name $mySite -AppSettings $setting -Slot production
Write-Host “Done!”</pre>
It is important for us to have a proper test automation as that will decide how reliable our automation is.

<strong>Conclusion</strong>

Putting all together, in this post we saw how easy it is for us to stitch everything together were we have Resources being created from Resource Template, build and release is automated, Application settings created automatically through PowerShell for Serverless Azure Functions. Adding a CICD trigger in VSO will turn this to a model where each code check-in will trigger as build and its corresponding release, This, in a way, will help us get our code to production much faster.

Hope this helps while working with Azure functions…

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

^Ganesh Shankaran]]></content:encoded>
    </item>
    <item>
      <title>How do we use custom  HTTP MessageHandler for validating multiple token issuers?</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/how-do-we-use-custom-http-messagehandler-for-validating-multiple-token-issuers</link>
      <pubDate>Sun, 12 Oct 2014 15:49:42 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/2014/10/12/how-do-we-use-custom-http-messagehandler-for-validating-multiple-token-issuers/</guid>
      <description><![CDATA[Before we get in to the solution of how we can handle multiple token issuer, I’m going to bring up...]]></description>
      <content:encoded><![CDATA[<p><font size="3"></font></p>  <p><font size="3" face="Segoe UI Light">Before we get in to the solution of how we can handle multiple token issuer, I’m going to bring up some of the fundamentals of how HTTP request/Response is handler to make a lot of sense out of the proposed solution. </font></p>  <p><font size="3"><font face="Segoe UI Light">Whenever a HTTP request is made, the call goes through the HTTP message handler and returns the HTTP response.</font><font face="Segoe UI Light"><strong> </strong>HttpMessageHandler abstract class is the base class for message Handler.</font> </font></p>  <p><strong><font size="3"></font></strong></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/38/metablogapi/0216.clip_image001_5A78A471.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-38-metablogapi/0216.clip_5F00_image001_5F00_5A78A471.png"><font size="3"><img title="clip_image001" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image001" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/38/metablogapi/1134.clip_image001_thumb_302E8DF8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-38-metablogapi/1134.clip_5F00_image001_5F00_thumb_5F00_302E8DF8.png" width="272" height="316" /></font></a></p>  <p><font size="3" face="Segoe UI Light">I sniped the above picture form </font><a href="https://www.asp.net/web-api/overview/advanced/http-message-handlers"><font size="3" face="Segoe UI Light">here</font></a><font size="3" face="Segoe UI Light"> which clearly explains how Message Handlers can be hooked inside the pipeline. As we notice, we can have multiple such custom message handler which we can chain it together. The first handler receives an HTTP request, does some processing, and gives the request to the next handler. At some point, the response is created and goes back up the chain. This pattern is called a <i>delegating</i> handler.</font></p>  <p><font size="3" face="Segoe UI Light">Our solution to go handle multiple token issuers is entirely based on HTTP MessageHandlers. We inherit DelegateHandler class and access the received token, we then will be able to go validate it based on the different issuers. </font></p>  <p><font size="3" face="Segoe UI Light">This technique is also followed basically to hook in to the request response and compress the message <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/38/metablogapi/0181.wlEmoticon-smile_21F2A5B9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-38-metablogapi/0181.wlEmoticon_2D00_smile_5F00_21F2A5B9.png" />, well that’s outside the discussion that we are having here. </font></p>  <p><font size="3" face="Segoe UI Light">Going back straight to the how we implement the message Handler especially with the introduction of OWIN middleware , it would be better for me to first summarize the steps before I include the code ( obviously without code this would be incomplete <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/38/metablogapi/0181.wlEmoticon-smile_21F2A5B9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-38-metablogapi/0181.wlEmoticon_2D00_smile_5F00_21F2A5B9.png" /> ) </font></p>  <p><font size="3" face="Segoe UI Light"></font></p>  <ul>   <li><font size="3" face="Segoe UI Light">Install the required Owin nugets (we also need Microsoft.Owin.Security.Jwt for Jwt token validation ) </font></li>    <li><font size="3" face="Segoe UI Light">Override SendAsunc() method, here is where our complete code of validation will reside. </font></li>    <li><font size="3" face="Segoe UI Light">Switch the validation process based on the different issuers ( In the sample I have include token that is issued by ACS and AAD ) </font></li>    <li><font size="3" face="Segoe UI Light">Set the claim principal post validation. </font></li>    <li><font size="3" face="Segoe UI Light">That’s it, we are good to go have a look at the code. </font></li>    <li><font size="3"><font face="Segoe UI Light">One more thing we should remember is to register the custom Token handler to the webAPIconfig, t</font><font face="Segoe UI Light">his come be done simply by adding the following piece of code in the webAPIConfig</font></font></li> </ul>  <pre><font size="3"></font></pre>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum1" style="color: #606060">   1:</span> config.MessageHandlers.Add(new TokenValidationHandler());</font></pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Segoe UI Light">coming to the TokenVaidationHandler class, this is how it goes;</font></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">internal</span> <span style="color: #0000ff">class</span> TokenValidationHandler : DelegatingHandler</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum2" style="color: #606060">   2:</span>   {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum3" style="color: #606060">   3:</span>       <span style="color: #008000">//</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum4" style="color: #606060">   4:</span>       <span style="color: #008000">// SendAsync checks that incoming requests have a valid access token, and sets the current user identity using that access token.</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum5" style="color: #606060">   5:</span>       <span style="color: #008000">//</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum6" style="color: #606060">   6:</span>       <span style="color: #0000ff">protected</span> async <span style="color: #0000ff">override</span> System.Threading.Tasks.Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum7" style="color: #606060">   7:</span>       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum8" style="color: #606060">   8:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum9" style="color: #606060">   9:</span>           <span style="color: #0000ff">try</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum10" style="color: #606060">  10:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum11" style="color: #606060">  11:</span>               String headerValue = HttpContext.Current.Request.Headers[<span style="color: #006080">&quot;Authorization&quot;</span>];</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum12" style="color: #606060">  12:</span>               <span style="color: #0000ff">if</span> (headerValue != <span style="color: #0000ff">null</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum13" style="color: #606060">  13:</span>               {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum14" style="color: #606060">  14:</span>                   JwtSecurityTokenHandler jwt_tokenhandler = <span style="color: #0000ff">new</span> JwtSecurityTokenHandler();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum15" style="color: #606060">  15:</span>                   <span style="color: #0000ff">string</span>[] tokenarray;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum16" style="color: #606060">  16:</span>                   <span style="color: #0000ff">string</span> token;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum17" style="color: #606060">  17:</span>                   <span style="color: #0000ff">if</span> (headerValue.Contains(<span style="color: #006080">&quot;Bearer&quot;</span>))</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum18" style="color: #606060">  18:</span>                   {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum19" style="color: #606060">  19:</span>                       tokenarray = headerValue.Substring(<span style="color: #006080">&quot;Bearer &quot;</span>.Length).Split(<span style="color: #0000ff">new</span> <span style="color: #0000ff">char</span>[] { <span style="color: #006080">'='</span> }, 2);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum20" style="color: #606060">  20:</span>                       token = tokenarray[0];</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum21" style="color: #606060">  21:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum22" style="color: #606060">  22:</span>                   }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum23" style="color: #606060">  23:</span>                   <span style="color: #0000ff">else</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum24" style="color: #606060">  24:</span>                   {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum25" style="color: #606060">  25:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum26" style="color: #606060">  26:</span>                       tokenarray = headerValue.Substring(<span style="color: #006080">&quot;WRAP &quot;</span>.Length).Split(<span style="color: #0000ff">new</span> <span style="color: #0000ff">char</span>[] { <span style="color: #006080">'='</span> }, 2);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum27" style="color: #606060">  27:</span>                       token = tokenarray[1].Substring(1, tokenarray[1].Length - 2);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum28" style="color: #606060">  28:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum29" style="color: #606060">  29:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum30" style="color: #606060">  30:</span>                   }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum31" style="color: #606060">  31:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum32" style="color: #606060">  32:</span>                   <span style="color: #0000ff">string</span> issuer = <span style="color: #006080">&quot;&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum33" style="color: #606060">  33:</span>                   TokenValidationParameters parms = <span style="color: #0000ff">new</span> System.IdentityModel.Tokens.TokenValidationParameters();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum34" style="color: #606060">  34:</span>                   <span style="color: #0000ff">string</span> aadInstance = <span style="color: #006080">&quot;&lt;aadInstance for login,this should have the domain information as well&gt; &quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum35" style="color: #606060">  35:</span>                   <span style="color: #0000ff">string</span> tenant = <span style="color: #006080">&quot;&lt;mydomain&gt;.onmicrosoft.com&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum36" style="color: #606060">  36:</span>                   <span style="color: #0000ff">string</span> authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum37" style="color: #606060">  37:</span>                   <span style="color: #0000ff">string</span> metadataAddress = <span style="color: #006080">&quot;&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum38" style="color: #606060">  38:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum39" style="color: #606060">  39:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum40" style="color: #606060">  40:</span>                   <span style="color: #0000ff">if</span> (token.Contains(<span style="color: #006080">&quot;Issuer&quot;</span>))</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum41" style="color: #606060">  41:</span>                   {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum42" style="color: #606060">  42:</span>                       <span style="color: #008000">// Check that it starts with 'WRAP'</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum43" style="color: #606060">  43:</span>                       <span style="color: #0000ff">if</span> (!headerValue.StartsWith(<span style="color: #006080">&quot;WRAP &quot;</span>))</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum44" style="color: #606060">  44:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum45" style="color: #606060">  45:</span>                           <span style="color: #0000ff">return</span> await Task.Factory.StartNew(() =&gt;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum46" style="color: #606060">  46:</span>                           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum47" style="color: #606060">  47:</span>                               <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> HttpResponseMessage(HttpStatusCode.Unauthorized)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum48" style="color: #606060">  48:</span>                               {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum49" style="color: #606060">  49:</span>                                   Content = <span style="color: #0000ff">new</span> StringContent(<span style="color: #006080">&quot;Invalid token&quot;</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum50" style="color: #606060">  50:</span>                               };</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum51" style="color: #606060">  51:</span>                           });</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum52" style="color: #606060">  52:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum53" style="color: #606060">  53:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum54" style="color: #606060">  54:</span>                       <span style="color: #0000ff">string</span>[] nameValuePair = headerValue.Substring(<span style="color: #006080">&quot;WRAP &quot;</span>.Length).Split(<span style="color: #0000ff">new</span> <span style="color: #0000ff">char</span>[] { <span style="color: #006080">'='</span> }, 2);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum55" style="color: #606060">  55:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum56" style="color: #606060">  56:</span>                       <span style="color: #0000ff">if</span> (nameValuePair.Length != 2 ||</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum57" style="color: #606060">  57:</span>                           nameValuePair[0] != <span style="color: #006080">&quot;access_token&quot;</span> ||</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum58" style="color: #606060">  58:</span>                           !nameValuePair[1].StartsWith(<span style="color: #006080">&quot;\&quot;&quot;</span>) ||</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum59" style="color: #606060">  59:</span>                           !nameValuePair[1].EndsWith(<span style="color: #006080">&quot;\&quot;&quot;</span>))</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum60" style="color: #606060">  60:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum61" style="color: #606060">  61:</span>                           <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ApplicationException(<span style="color: #006080">&quot;unauthorized&quot;</span>);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum62" style="color: #606060">  62:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum63" style="color: #606060">  63:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum64" style="color: #606060">  64:</span>                   }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum65" style="color: #606060">  65:</span>                   <span style="color: #0000ff">else</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum66" style="color: #606060">  66:</span>                   {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum67" style="color: #606060">  67:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum68" style="color: #606060">  68:</span>                       JwtSecurityToken secToken = jwt_tokenhandler.ReadToken(token) <span style="color: #0000ff">as</span> JwtSecurityToken;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum69" style="color: #606060">  69:</span>                       <span style="color: #0000ff">if</span> (secToken != <span style="color: #0000ff">null</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum70" style="color: #606060">  70:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum71" style="color: #606060">  71:</span>                           issuer = secToken.Issuer;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum72" style="color: #606060">  72:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum73" style="color: #606060">  73:</span>                       <span style="color: #0000ff">if</span> (issuer == <span style="color: #006080">&quot;https://&lt;my-acs&gt;.accesscontrol.windows.net/&quot;</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum74" style="color: #606060">  74:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum75" style="color: #606060">  75:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum76" style="color: #606060">  76:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum77" style="color: #606060">  77:</span>                           metadataAddress = <span style="color: #006080">&quot;https://&lt;my-acs&gt;.accesscontrol.windows.net/FederationMetadata/2007-06/FederationMetadata.xml&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum78" style="color: #606060">  78:</span>                           List&lt;X509SecurityToken&gt; signingTokens;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum79" style="color: #606060">  79:</span>                           GetTenantInformation(metadataAddress, <span style="color: #0000ff">out</span> issuer, <span style="color: #0000ff">out</span> signingTokens);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum80" style="color: #606060">  80:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum81" style="color: #606060">  81:</span>                           parms.ValidIssuer = issuer;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum82" style="color: #606060">  82:</span>                           parms.CertificateValidator = System.IdentityModel.Selectors.X509CertificateValidator.None;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum83" style="color: #606060">  83:</span>                           parms.IssuerSigningTokens = signingTokens;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum84" style="color: #606060">  84:</span>                           parms.ValidAudience = <span style="color: #006080">&quot;&lt;valid ACS on-boarded  Audience&gt;&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum85" style="color: #606060">  85:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum86" style="color: #606060">  86:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum87" style="color: #606060">  87:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum88" style="color: #606060">  88:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum89" style="color: #606060">  89:</span>                       <span style="color: #0000ff">else</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum90" style="color: #606060">  90:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum91" style="color: #606060">  91:</span>                           <span style="color: #0000ff">string</span> stsDiscoveryEndpoint = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}/.well-known/openid-configuration&quot;</span>, authority);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum92" style="color: #606060">  92:</span>                           <span style="color: #008000">// Get tenant information that's used to validate incoming jwt tokens</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum93" style="color: #606060">  93:</span>                           ConfigurationManager&lt;OpenIdConnectConfiguration&gt; configManager = <span style="color: #0000ff">new</span> ConfigurationManager&lt;OpenIdConnectConfiguration&gt;(stsDiscoveryEndpoint);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum94" style="color: #606060">  94:</span>                           OpenIdConnectConfiguration config = await configManager.GetConfigurationAsync();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum95" style="color: #606060">  95:</span>                           List&lt;SecurityToken&gt; signingTokens = config.SigningTokens.ToList();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum96" style="color: #606060">  96:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum97" style="color: #606060">  97:</span>                           parms.ValidIssuer = <span style="color: #006080">&quot;https://sts.windows.net/&lt;respective guid&gt;/&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum98" style="color: #606060">  98:</span>                           parms.CertificateValidator = System.IdentityModel.Selectors.X509CertificateValidator.None;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum99" style="color: #606060">  99:</span>                           parms.IssuerSigningTokens = signingTokens;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum100" style="color: #606060"> 100:</span>                           parms.ValidAudience = <span style="color: #006080">&quot;&lt;valid AAD on-boarded Audience&gt;&quot;</span>;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum101" style="color: #606060"> 101:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum102" style="color: #606060"> 102:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum103" style="color: #606060"> 103:</span>                       SecurityToken validatedToken = <span style="color: #0000ff">new</span> JwtSecurityToken();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum104" style="color: #606060"> 104:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum105" style="color: #606060"> 105:</span>                       var principal = jwt_tokenhandler.ValidateToken(token, parms, <span style="color: #0000ff">out</span> validatedToken);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum106" style="color: #606060"> 106:</span>                       <span style="color: #008000">// Set the ClaimsPrincipal on HttpContext.Current if the app is running in web hosted environment.</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum107" style="color: #606060"> 107:</span>                       <span style="color: #0000ff">if</span> (HttpContext.Current != <span style="color: #0000ff">null</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum108" style="color: #606060"> 108:</span>                       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum109" style="color: #606060"> 109:</span>                           HttpContext.Current.User = principal;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum110" style="color: #606060"> 110:</span>                       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum111" style="color: #606060"> 111:</span>                       System.Threading.Thread.CurrentPrincipal = principal;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum112" style="color: #606060"> 112:</span>                   }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum113" style="color: #606060"> 113:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum114" style="color: #606060"> 114:</span>                   </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum115" style="color: #606060"> 115:</span>               }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum116" style="color: #606060"> 116:</span>               <span style="color: #0000ff">return</span> await <span style="color: #0000ff">base</span>.SendAsync(request, cancellationToken);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum117" style="color: #606060"> 117:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum118" style="color: #606060"> 118:</span>           }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum119" style="color: #606060"> 119:</span>           <span style="color: #0000ff">catch</span> (Exception ex)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum120" style="color: #606060"> 120:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum121" style="color: #606060"> 121:</span>               HttpResponseMessage response = BuildResponseErrorMessage(HttpStatusCode.Unauthorized);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum122" style="color: #606060"> 122:</span>               <span style="color: #0000ff">return</span> response;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum123" style="color: #606060"> 123:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum124" style="color: #606060"> 124:</span>           }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum125" style="color: #606060"> 125:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum126" style="color: #606060"> 126:</span>  </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum127" style="color: #606060"> 127:</span>       }</font></pre>
<!--CRLF--></div>
</div>

<p><font size="3"><font face="Segoe UI Light">For extracting the tenant issuer information form the signing in token we can use the below code which parses the token against the MetadataAddress (for accessing the certificate) and sets the issuer and the signingTokens.</font> </font></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum1" style="color: #606060">   1:</span> static void GetTenantInformation(string metadataAddress, out string issuer, out List<span style="color: #0000ff">&lt;</span><span style="color: #800000">X509SecurityToken</span><span style="color: #0000ff">&gt;</span> signingTokens)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum2" style="color: #606060">   2:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum3" style="color: #606060">   3:</span>       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum4" style="color: #606060">   4:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum5" style="color: #606060">   5:</span>           signingTokens = new List<span style="color: #0000ff">&lt;</span><span style="color: #800000">X509SecurityToken</span><span style="color: #0000ff">&gt;</span>();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum6" style="color: #606060">   6:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum7" style="color: #606060">   7:</span>           issuer = null;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum8" style="color: #606060">   8:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum9" style="color: #606060">   9:</span> MetadataSerializer serializer = new MetadataSerializer()</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum10" style="color: #606060">  10:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum11" style="color: #606060">  11:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum12" style="color: #606060">  12:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum13" style="color: #606060">  13:</span> //CertificateValidationMode = X509CertificateValidationMode.None</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum14" style="color: #606060">  14:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum15" style="color: #606060">  15:</span>           };</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum16" style="color: #606060">  16:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum17" style="color: #606060">  17:</span> MetadataBase metadata = serializer.ReadMetadata(XmlReader.Create(metadataAddress));</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum18" style="color: #606060">  18:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum19" style="color: #606060">  19:</span> EntityDescriptor entityDescriptor = (EntityDescriptor)metadata;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum20" style="color: #606060">  20:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum21" style="color: #606060">  21:</span> // get the issuer name </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum22" style="color: #606060">  22:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum23" style="color: #606060">  23:</span> if (!string.IsNullOrWhiteSpace(entityDescriptor.EntityId.Id))</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum24" style="color: #606060">  24:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum25" style="color: #606060">  25:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum26" style="color: #606060">  26:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum27" style="color: #606060">  27:</span>               issuer = entityDescriptor.EntityId.Id;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum28" style="color: #606060">  28:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum29" style="color: #606060">  29:</span>           }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum30" style="color: #606060">  30:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum31" style="color: #606060">  31:</span> // get the signing certs </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum32" style="color: #606060">  32:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum33" style="color: #606060">  33:</span>           signingTokens = ReadSigningCertsFromMetadata(entityDescriptor);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum34" style="color: #606060">  34:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum35" style="color: #606060">  35:</span>       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum36" style="color: #606060">  36:</span>&#160; </font></pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Segoe UI Light">In order for us to read the signing Certs from the entityDesciptor from the above code we use the below method</font></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">static</span> List&lt;X509SecurityToken&gt; ReadSigningCertsFromMetadata(EntityDescriptor entityDescriptor)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum2" style="color: #606060">   2:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum3" style="color: #606060">   3:</span>       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum4" style="color: #606060">   4:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum5" style="color: #606060">   5:</span> List&lt;X509SecurityToken&gt; stsSigningTokens = <span style="color: #0000ff">new</span> List&lt;X509SecurityToken&gt;();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum6" style="color: #606060">   6:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum7" style="color: #606060">   7:</span> SecurityTokenServiceDescriptor stsd = entityDescriptor.RoleDescriptors.OfType&lt;SecurityTokenServiceDescriptor&gt;().First();</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum8" style="color: #606060">   8:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #0000ff">if</span> (stsd != <span style="color: #0000ff">null</span> &amp;&amp; stsd.Keys != <span style="color: #0000ff">null</span>)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum10" style="color: #606060">  10:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum11" style="color: #606060">  11:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum12" style="color: #606060">  12:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum13" style="color: #606060">  13:</span> IEnumerable&lt;X509RawDataKeyIdentifierClause&gt; x509DataClauses = stsd.Keys.Where(key =&gt; key.KeyInfo != <span style="color: #0000ff">null</span> &amp;&amp; (key.Use == KeyType.Signing || key.Use == KeyType.Unspecified)).</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum14" style="color: #606060">  14:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum15" style="color: #606060">  15:</span>                                                            Select(key =&gt; key.KeyInfo.OfType&lt;X509RawDataKeyIdentifierClause&gt;().First());</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum16" style="color: #606060">  16:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum17" style="color: #606060">  17:</span>               stsSigningTokens.AddRange(x509DataClauses.Select(clause =&gt; <span style="color: #0000ff">new</span> X509SecurityToken(<span style="color: #0000ff">new</span> X509Certificate2(clause.GetX509RawData()))));</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum18" style="color: #606060">  18:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum19" style="color: #606060">  19:</span>           }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum20" style="color: #606060">  20:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum21" style="color: #606060">  21:</span> <span style="color: #0000ff">else</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum22" style="color: #606060">  22:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum23" style="color: #606060">  23:</span>           {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum24" style="color: #606060">  24:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum25" style="color: #606060">  25:</span> <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> InvalidOperationException(<span style="color: #006080">&quot;There is no RoleDescriptor of type SecurityTokenServiceType in the metadata&quot;</span>);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum26" style="color: #606060">  26:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum27" style="color: #606060">  27:</span>           }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum28" style="color: #606060">  28:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum29" style="color: #606060">  29:</span> <span style="color: #0000ff">return</span> stsSigningTokens;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum30" style="color: #606060">  30:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum31" style="color: #606060">  31:</span>       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum32" style="color: #606060">  32:</span>&#160; </font></pre>
<!--CRLF--></div>
</div>

<p><font size="3"></font></p>

<p><font size="3" face="Segoe UI Light">The below code is basically to Build the response Message based on the HTTP statusCode. </font></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">private</span> HttpResponseMessage BuildResponseErrorMessage(HttpStatusCode statusCode)</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum2" style="color: #606060">   2:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum3" style="color: #606060">   3:</span>       {</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum4" style="color: #606060">   4:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum5" style="color: #606060">   5:</span> HttpResponseMessage response = <span style="color: #0000ff">new</span> HttpResponseMessage(statusCode);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum6" style="color: #606060">   6:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum7" style="color: #606060">   7:</span> <span style="color: #008000">//</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum8" style="color: #606060">   8:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #008000">// The Scheme should be &quot;Bearer&quot;, authorization_uri should point to the tenant url and resource_id should point to the audience.</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum10" style="color: #606060">  10:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum11" style="color: #606060">  11:</span> <span style="color: #008000">//</span></font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum12" style="color: #606060">  12:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum13" style="color: #606060">  13:</span> AuthenticationHeaderValue authenticateHeader = <span style="color: #0000ff">new</span> AuthenticationHeaderValue(<span style="color: #006080">&quot;Bearer&quot;</span>, <span style="color: #006080">&quot;unathorized&quot;</span>);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum14" style="color: #606060">  14:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum15" style="color: #606060">  15:</span>           response.Headers.WwwAuthenticate.Add(authenticateHeader);</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum16" style="color: #606060">  16:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum17" style="color: #606060">  17:</span> <span style="color: #0000ff">return</span> response;</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum18" style="color: #606060">  18:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum19" style="color: #606060">  19:</span>       }</font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><font size="3"><span id="lnum20" style="color: #606060">  20:</span>&#160; </font></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><font size="3"><span id="lnum21" style="color: #606060">  21:</span>   }</font></pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Segoe WP Light">Connecting the above Token Validator code we should be able to handle multiple token issuers in one Message handler. This might be of some use to those who are trying to handle multiple issuers <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none" alt="Smile" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/50/38/metablogapi/0181.wlEmoticon-smile_21F2A5B9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-38-metablogapi/0181.wlEmoticon_2D00_smile_5F00_21F2A5B9.png" />. Please note that this is not a production ready code and the sole purpose of this is to depict how we can hook in Message handler for token validation. This would need further testing based on the varied scenario before its been used. </font></p>

<p><font size="3" face="Segoe WP Light">Happy Coding!</font></p>

<p><font size="3"></font></p>

<p><font size="3"></font></p>

<p><font size="3"></font></p>

<p><font size="3"></font></p>

<p><font size="3" face="Segoe UI Light">^Ganesh Shankaran</font></p>]]></content:encoded>
    </item>
    <item>
      <title>ASP .NET Authentication : OWIN middleware component for browser based sign-on using WsFederation</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/asp-net-authentication-owin-middleware-component-for-browser-based-sign-on-using-wsfederation</link>
      <pubDate>Sat, 20 Sep 2014 03:25:00 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/2014/09/20/asp-net-authentication-owin-middleware-component-for-browser-based-sign-on-using-wsfederation/</guid>
      <description><![CDATA[Authentication of ASP .NET Web API using OWIN middleware component with Azure active Directory is...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: verdana,geneva;">Authentication of ASP .NET Web API using OWIN middleware component with Azure active Directory is made so easy which we all know. For the matter of fact, the Visual studio integration&nbsp; to choose different types of authentication during the creation of Web API made developers life easy compared to the previous ways of&nbsp; onboarding Authentication through identity </span><span style="font-family: verdana,geneva;">tooling[I'm sure we all remember the huge web.config :) ] . The&nbsp; new OWIN-based programming model for securing modern ASP.NET applications simply changes the way in which developers think about claim based identity and its integration with their web application.</span></p>
<p><span style="font-family: verdana,geneva;">OWIN components allow you to secure your ASP.NET applications with Windows Azure AD, ADFS and any other identity provider supporting WS-Federation.</span></p>
<p><span style="font-family: verdana,geneva;">Microsoft OWIN components has been explained in great detail in the <a href="https://msdn.microsoft.com/en-us/magazine/dn451439.aspx">article</a> and&nbsp; to those who feel OWIN is new can definitely refer to <a href="https://msdn.microsoft.com/en-us/magazine/dn451439.aspx">this</a>.&nbsp; Btw, to those who want to read about _OWIN specification_ I would recommend reading&nbsp; <a href="https://owin.org/">https://owin.org/</a>&nbsp; which has all the wealth of information about OWIN[Open Web Interface for .NET ].</span></p>
<p><span style="font-family: verdana,geneva;">Today to secure our ASP .NET web application that is integrated with Visual Studio we follow a simple initialization logic&nbsp; with a simple code,&nbsp; we can read about the flow&nbsp; <a href="https://msdn.microsoft.com/en-us/magazine/dn463788.aspx">here</a>.</span></p>
<p><span style="font-family: verdana,geneva;">The default project today when we create from Visual studio has the following piece of code;</span></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 97.5%; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> Startup</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;"> 2:</span>     {</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;"> 3:</span>         <span style="color: #008000;">// For more information on configuring authentication, please visit https://go.microsoft.com/fwlink/?LinkId=301864</span></pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;"> 4:</span>        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> ConfigureAuth(IAppBuilder app)</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;"> 5:</span>         {</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;"> 6:</span>             app.UseWindowsAzureActiveDirectoryBearerAuthentication(</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;"> 7:</span>                 <span style="color: #0000ff;">new</span> WindowsAzureActiveDirectoryBearerAuthenticationOptions</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;"> 8:</span>                 {</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;"> 9:</span>                     Audience = ConfigurationManager.AppSettings[<span style="color: #006080;">"ida:Audience"</span>],</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;"> 10:</span>                      Tenant = ConfigurationManager.AppSettings[<span style="color: #006080;">"ida:Tenant"</span>]</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;"> 11:</span>                 });</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;"> 12:</span>         }</pre>
<!--CRLF-->
<pre style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;"> 13:</span>     }</pre>
<!--CRLF--></div>
</div>
<p><span style="font-family: verdana,geneva;">The audience and the Tenant information is pulled from the configuration and that&rsquo;s it.. All of it is wired. There are is a lot of configuration that has been reduced and I'm sure people who have been working on the identity integration with the earlier approaches will definitely appreciate the work by&nbsp; Windows Azure Active Directory team, Kudos to them :).</span></p>
<p><span style="font-family: verdana,geneva;">There was a question that came to me during discuss with my friends on how we can enable browser based sign on having to work seamlessly with the OWIN middleware and I though while I answer his question, can quickly post it&nbsp; here as well, as this might help others who are looking for the same &hellip;</span></p>
<p><span style="font-family: verdana,geneva;">Coming straight to the Point, Microsoft.Owin.Security.WsFederation&nbsp; <a href="https://www.nuget.org/packages/Microsoft.Owin.Security.WsFederation/">Nuget</a> does the magic of how we can have browser based sign on.. For us to have this one to our project, we need to add the below snip of code into ConfigureAuth method of the Startup class ;</span></p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;">
<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;">
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: #606060;"> 1:</span> app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum2" style="color: #606060;"> 2:</span>            app.UseCookieAuthentication(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: #606060;"> 3:</span>                <span style="color: #0000ff;">new</span> CookieAuthenticationOptions</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum4" style="color: #606060;"> 4:</span>                {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: #606060;"> 5:</span>                    AuthenticationType =</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum6" style="color: #606060;"> 6:</span>                       WsFederationAuthenticationDefaults.AuthenticationType</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: #606060;"> 7:</span>                });</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum8" style="color: #606060;"> 8:</span>            app.UseWsFederationAuthentication(</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: #606060;"> 9:</span>                <span style="color: #0000ff;">new</span> WsFederationAuthenticationOptions</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum10" style="color: #606060;"> 10:</span>                {</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: #606060;"> 11:</span>                     MetadataAddress = <span style="color: #006080;">"&lt;Federated Metadata&gt;"</span>,</pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"><span id="lnum12" style="color: #606060;"> 12:</span>                    Wtrealm = <span style="color: #006080;">"&lt;your realm&gt;"</span></pre>
<!--CRLF-->
<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: #606060;"> 13:</span>                });</pre>
<!--CRLF--></div>
</div>
<p><span style="font-family: verdana,geneva;"></span></p>
<p><span style="font-size: small; font-family: verdana,geneva;"><span style="background: white; color: black;">&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: verdana,geneva;">This <a href="https://msdn.microsoft.com/en-us/library/microsoft.owin.security.wsfederation.wsfederationauthenticationoptions%28v=vs.113%29.aspx">link</a> explains in details of how we can use WsFederationAuthenicationOptions. In short below are the values that we need to set it up to have the passive federation browser </span><span style="font-family: verdana,geneva;">based login to work.</span></p>
<p><br /><span style="font-family: verdana,geneva;"><strong>Wtrealm</strong>:&nbsp; This is the identifier of your application, as assigned when you configured your app in your authenticating authority (in the Windows Azure portal for Windows Azure AD, in the management console for ADFS).</span> <br />&nbsp; <br /><span style="font-family: verdana,geneva;"><strong>MetadataAddress</strong> : This value represents the Windows Azure AD tenant (or ADFS instance) you want to use for authenticating your users. If you are writing line of business apps for your own company, this line will likely never change.</span></p>
<p><span style="font-family: verdana,geneva;">If we are wondering about the CookieAuthentication that is added in the above snip of code, it&rsquo;s the OWIN Cookie Authentication middleware component (we can be downloaded from Microsoft.Owin.Security.Cookie&nbsp; <span style="font-size: 11pt; font-family: 'Segoe UI Light','sans-serif'; color: black; mso-fareast-font-family: calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: en-us; mso-fareast-language: en-us; mso-bidi-language: ar-sa;"><a href="https://www.nuget.org/packages/Microsoft.Owin.Security.Cookies/">nuget</a></span>) which not only performs the operation of issuing the cookie and validating the cookie on the subsequent request but also the converts&nbsp; the response and redirect to the login page upon failure. The best part of this middle ware is that it is claim-aware ..</span></p>
<p><span style="font-family: verdana,geneva;">Hope this helps someone who is trying to get the OWIN middleware for enabling browser based sign-on using WsFederation&hellip; Happy coding!</span></p>
<p><span style="font-family: verdana,geneva;">Ganesh Shankaran</span></p>
<p><span style="font-family: verdana,geneva;">Software Development Engineer </span></p>]]></content:encoded>
    </item>
    <item>
      <title>Azure Caching: All that we need to know</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/azure-caching-all-that-we-need-to-know</link>
      <pubDate>Tue, 02 Sep 2014 21:20:00 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/2014/09/02/azure-caching-all-that-we-need-to-know/</guid>
      <description><![CDATA[Why Caching?
As load increases on a web application, we will often take a series of steps to help...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: verdana,geneva; font-size: medium;">Why Caching?</span></p>
<p><span style="font-family: verdana,geneva;">As load increases on a web application, we will often take a series of steps to help improve site performance. Initially, we might put our web application behind a load balancer and add more web instances to better serve the incoming requests. With Windows Azure Web Sites and Cloud Services, adding more instances is as easy a turning a knob to the number of desired instances. The Windows Azure load balancer automatically adjusts to handle the additional instances. </span></p>
<p class="paragraph"><span style="font-family: verdana,geneva;">Our next step might be to add more, or perhaps even larger, application servers to our middle / business logic tier. But as traffic continues to increase, the load on our database typically starts to increase as well. Soon the database may become the performance bottleneck. The database responses can get slower and slower. As pressure increases, the database may begin to throttle or connections may timeout. The end result for our users &ndash; errors and a poor experience.</span></p>
<p><span style="font-family: verdana,geneva; font-size: medium;">Different Azure Cache Offerings from Microsoft and there supportability </span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Cache</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Also</span><br /><span style="font-family: verdana,geneva;">&nbsp; referred as</span></p>
</td>
<td valign="top" width="157">
<p class="paragraph"><span style="font-family: verdana,geneva;">&nbsp;Supportability</span></p>
</td>
<td valign="top" width="458">
<p class="paragraph"><span style="font-family: verdana,geneva;">Details</span></p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">In-Role Cache</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="157">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="458">
<p class="paragraph">&nbsp;<span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://msdn.microsoft.com/en-us/library/azure/hh914161.aspx">About<br />&nbsp; In-role cache : https://msdn.microsoft.com/en-us/library/azure/hh914161.aspx</a></span></p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="font-family: verdana,geneva;">&nbsp; Dedicated Cache</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Role based Cache</span></p>
</td>
<td valign="top" width="157">
<p class="paragraph"><span style="font-family: verdana,geneva;">Supported</span></p>
</td>
<td valign="top" width="458">
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://msdn.microsoft.com/en-us/library/azure/hh914161.aspx"><br /></a></span></p>
<p><a href="https://msdn.microsoft.com/en-us/library/azure/hh914140.aspx">https://msdn.microsoft.com/en-us/library/azure/hh914140.aspx</a></p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="font-family: verdana,geneva;">&nbsp; Co-Located Cache</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Windows Azure Cache</span></p>
</td>
<td valign="top" width="157">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="458">
<p class="paragraph">&nbsp;</p>
<p>&nbsp;<a href="https://msdn.microsoft.com/en-us/library/azure/hh914128.aspx">https://msdn.microsoft.com/en-us/library/azure/hh914128.aspx</a></p>
<p class="paragraph">&nbsp;</p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="156">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="157">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="458">
<p class="paragraph">&nbsp;</p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Azure Shared Cache&nbsp;</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Azure AppFabric Cache</span></p>
</td>
<td valign="top" width="157">
<p class="paragraph"><span style="font-family: verdana,geneva;">Goes out of service on</span><br /><span style="font-family: verdana,geneva;">&nbsp; September 1st 2014</span></p>
</td>
<td width="458">
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://msdn.microsoft.com/en-us/library/azure/hh914133.aspx">https://msdn.microsoft.com/en-us/library/azure/hh914133.aspx</a></span></p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Azure Cache Service</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Azure Managed Cache</span></p>
</td>
<td valign="top" width="157">
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://go.microsoft.com/?linkid=9811175">Supported(Not Recommended).<br />&nbsp; Don&rsquo;t support the ability to create a managed cached in the portal today, you<br />&nbsp; will need use the Azure PowerShell SDK to create a cache </a></span></p>
</td>
<td width="458">
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://msdn.microsoft.com/en-us/library/azure/dn386094.aspx">https://msdn.microsoft.com/en-us/library/azure/dn386094.aspx</a></span></p>
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;">Why do we have<br />&nbsp; support for Azure managed service? <a href="https://msdn.microsoft.com/en-us/library/azure/dn690523.aspx">To support<br />&nbsp; customers who made investments into the preview offering of Azure Managed<br />&nbsp; Cache Service, who have dependency on it in their apps, and to give them as<br />&nbsp; much time as they need to move to Azure Redis Cache (Preview).</a></span></p>
</td>
</tr>
<tr>
<td valign="top" width="156">
<p class="paragraph"><span style="font-family: verdana,geneva;">Azure Redis Cache</span></p>
</td>
<td valign="top" width="156">
<p class="paragraph">&nbsp;</p>
</td>
<td valign="top" width="157">
<p class="paragraph"><span style="font-family: verdana,geneva;">Supported (Recommended)</span></p>
</td>
<td width="458">
<p class="paragraph"><span style="font-family: verdana,geneva; text-decoration: underline;"><a href="https://msdn.microsoft.com/en-us/library/azure/7c679300-07cc-4ba1-b8fa-39421b570d56#AzureRedisCache">https://msdn.microsoft.com/en-us/library/azure/7c679300-07cc-4ba1-b8fa-39421b570d56#AzureRedisCache</a></span></p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: medium;">Migration from Azure Shared Caching or AppFabric Caching</span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="233">
<p class="paragraph"><span style="font-family: verdana,geneva;">Migration from AppFabric Caching</span></p>
</td>
<td valign="top" width="300">
<p class="paragraph"><span style="font-family: verdana,geneva;"><a href="https://msdn.microsoft.com/en-us/library/azure/dn789051.aspx">https://msdn.microsoft.com/en-us/library/azure/dn789051.aspx</a></span><br />&nbsp;</p>
</td>
</tr>
<tr>
<td valign="top" width="233">
<p class="paragraph"><span style="font-family: verdana,geneva;">Migrate from Shared Caching to Azure</span><br /><span style="font-family: verdana,geneva;">&nbsp; Managed Cache Service</span></p>
</td>
<td valign="top" width="300">
<p class="paragraph"><span style="font-family: verdana,geneva;"><a href="https://msdn.microsoft.com/en-us/library/azure/dn386110.aspx">https://msdn.microsoft.com/en-us/library/azure/dn386110.aspx</a></span><br />&nbsp;</p>
</td>
</tr>
<tr>
<td valign="top" width="233">
<p class="paragraph"><span style="font-family: verdana,geneva;">Migrate from Shared Caching to Azure</span><br /><span style="font-family: verdana,geneva;">&nbsp; Redis Cache (Preview)</span></p>
</td>
<td valign="top" width="300">
<p class="paragraph"><span style="font-family: verdana,geneva;"><a href="https://msdn.microsoft.com/en-us/library/azure/dn690524.aspx">https://msdn.microsoft.com/en-us/library/azure/dn690524.aspx</a></span><br />&nbsp;</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: medium;">Usage Guidelines For a Co-located In-role Cache (ref: <a href="https://msdn.microsoft.com/en-us/library/azure/hh914128.aspx">link</a> <span style="font-family: verdana,geneva; font-size: medium;">)</span><br /></span></p>
<p><span style="font-family: verdana,geneva;">&nbsp;1.&nbsp;&nbsp;&nbsp; Use diagnostics data to determine the correct percentage of memory to allocate for caching. Include performance counter data on memory and CPU for the virtual machine instances that are running under expected load. The amount of memory available per running role instance is determined by the virtual machine size (VM size) and the memory used by the operating system and other application services running on the role. To understand how to correctly set the Cache Size (%), see Capacity Planning Considerations for In-Role Cache (Azure Cache).</span></p>
<p><br /><span style="font-family: verdana,geneva;">&nbsp;2.&nbsp;&nbsp;&nbsp; A co-located topology is not recommended in the following cases: </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; Cache sizes greater than 1.5 GB.&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; Cache clusters with more than 400 caching transactions per second per role instance&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; Cache clusters with more than 1.2 MB of bandwidth used for caching operations per second per role instance. </span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: medium;">Usage Guidelines for a Dedicated Caching Topology (ref: <a href="https://msdn.microsoft.com/en-us/library/azure/hh914140.aspx">link</a> <span style="font-family: verdana,geneva; font-size: medium;">)</span><br /></span></p>
<p class="paragraph"><span style="font-family: verdana,geneva;">&nbsp;The following guidelines apply to the dedicated In-Role Cache topology:&nbsp;</span></p>
<p><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp;&nbsp; In general, a dedicated InRole Cache role provides the best performance, because it does not share the role's virtual machine with any other application services. It also provides the most flexibility, because you can scale the In-Role Cache role independently. For these reasons, using a dedicated topology is the recommended caching architecture. However, there are situations where a co-located topology works well. For more information, see Guidelines for a Co-located Caching Topology.&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; The amount of memory available per running role instance is determined by the virtual machine size (VM size) and the memory used by the operating system and other application services running on the role. To understand how to correctly set the Cache Size (%), see Capacity Planning Considerations for In-Role Cache (Azure Cache).&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp;&nbsp; Do not use a dedicated In-Role Cache role for other code or services.&nbsp;&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; Only one cache cluster is supported for each cloud service. </span>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: verdana,geneva; font-size: medium;">What is the recommendation of Microsoft in choosing between the available options? (ref: <a href="https://msdn.microsoft.com/en-us/library/azure/dn766201.aspx">link</a> <span style="font-family: verdana,geneva; font-size: medium;">)</span><br /></span></p>
<p><span style="font-family: verdana,geneva;">There are always benefits of one over the other when it comes to selection of Caching methods, for example Azure managed service gives a capacity of 150 GB cache size when compared to Redis cache which is 26 GB.&nbsp; That being said, Azure Redis Cache gives customers the ability to use a secure, dedicated Redis cache, managed by Microsoft. With this offer, you get to leverage the rich feature set and ecosystem provided by Redis, and reliable hosting and monitoring from Microsoft. </span></p>
<p><span style="font-family: verdana,geneva;">On May 12, 2014, Microsoft announced the availability of the Azure Redis Cache (Preview). Microsoft recommend all new developments use the Azure Redis Cache.&nbsp; For more information please refer this <a href="https://msdn.microsoft.com/en-us/library/azure/dn766201.aspx">link</a> <br /></span></p>
<p><span style="font-family: verdana,geneva;">Other features of Azure&nbsp; Redis Cache include :&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp; Redis is an advanced key-value store, where keys can contain data structures such as strings, hashes, lists, sets and sorted sets. Redis supports a set of atomic operations on these data types.&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull; &nbsp; Transactions, Pub/Sub, Lua scripting, Keys with a limited time-to-live, and configuration settings to make Redis behave like a cache.&nbsp; </span><br /><span style="font-family: verdana,geneva;">&bull;&nbsp;&nbsp;&nbsp;Azure Redis Cache (Preview) leverages Redis authentication and also supports SSL connections to Redis. </span></p>
<p>&nbsp;</p>
<p class="paragraph">&nbsp;</p>
<p><span style="font-family: verdana,geneva;"><span style="font-size: medium;">Tutorial and Guide for Cache</span>: <a href="https://azure.microsoft.com/en-us/documentation/services/cache/">https://azure.microsoft.com/en-us/documentation/services/cache/</a>&nbsp;</span></p>
<p class="paragraph"><span style="font-family: verdana,geneva; font-size: medium;">Sample Demo&rsquo;s</span></p>
<table border="1" cellpadding="0">
<tbody>
<tr>
<td>
<p><span style="font-family: verdana,geneva;">Type&nbsp;&nbsp;</span></p>
</td>
<td>
<p><span style="font-family: verdana,geneva;">Sample&nbsp;&nbsp;</span></p>
</td>
</tr>
<tr>
<td>
<p><span style="font-family: verdana,geneva;">In-Role&nbsp;&nbsp;</span></p>
</td>
<td>
<p><span style="font-family: verdana,geneva;"><a href="https://msdn.microsoft.com/en-us/library/azure/gg278344.aspx">https://msdn.microsoft.com/en-us/library/azure/gg278344.aspx</a>&nbsp;</span></p>
</td>
</tr>
<tr>
<td>
<p><span style="font-family: verdana,geneva;">Azure Redis Cache&nbsp;</span></p>
</td>
<td>
<p><span style="font-family: verdana,geneva;"><a href="https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-azure-redis-cache/">https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-azure-redis-cache/</a>&nbsp;</span></p>
<p><span style="font-family: verdana,geneva;"><a href="https://azure.microsoft.com/blog/2014/06/05/mvc-movie-app-with-azure-redis-cache-in-15-minutes/">https://azure.microsoft.com/blog/2014/06/05/mvc-movie-app-with-azure-redis-cache-in-15-minutes/</a>&nbsp;</span></p>
</td>
</tr>
<tr>
<td>
<p><span style="font-family: verdana,geneva;">Azure Managed Cache&nbsp;</span></p>
</td>
<td>
<p><span style="font-family: verdana,geneva;"><a href="https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-service/">https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-service/</a>&nbsp;</span></p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p class="paragraph"><span style="font-family: verdana,geneva;">Now, that&rsquo;s some facts and basic information one must know while working on Azure Caching. This brings all the information from different msdn articles into one. </span></p>
<p class="paragraph"><span style="font-family: verdana,geneva;">For those who have already started using Azure Cache I&rsquo;m sure you would have seen(I have come across this pretty often)&nbsp; sometimes that the DataCacheFactory gets into a bad state where many requests will fail even though the server is fine. My next post will have details on handling DataCacheFactory by clearing DataCachefactory connectionPool. </span></p>
<p class="paragraph"><span style="font-family: verdana,geneva;">I hope this will help developers who start there Azure Cache journey.&nbsp;</span></p>
<p class="paragraph">&nbsp;</p>
<p class="paragraph"><span style="font-family: verdana,geneva;">Ganesh Shankaran</span></p>
<p class="paragraph"><span style="font-family: verdana,geneva;">Software Development Engineer</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Why do we get System.InvalidCastException when we read through custom Configuration file?</title>
      <link>https://docs.microsoft.com/archive/blogs/troubleshooting_tips_for_developers/why-do-we-get-system-invalidcastexception-when-we-read-through-custom-configuration-file</link>
      <pubDate>Fri, 13 Jan 2012 01:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Ganesh Shankaran]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/troubleshooting_tips_for_developers/2012/01/13/why-do-we-get-system-invalidcastexception-when-we-read-through-custom-configuration-file/</guid>
      <description><![CDATA[A developer’s life becomes a lot easier by using configuration files.&#160; Configuration files,...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small; font-family: verdana,geneva; color: #000000">A developer’s life becomes a lot easier by using configuration files.&#160; Configuration files, being XML files, can be changed as needed and developers can use configuration files to change settings without recompiling applications. Administrators can use configuration files to set policies that affect how applications run on their computers. </span>    <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">Managed code can use the classes in the System.Configuration namespace to read settings from the configuration files. When we read through the configuration files, there are certain scenarios which will lead to an&#160; System.InvalidcastException</span>    <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">If you have distinct groupings of configurations to be included in the application configuration file, consider creating a custom configuration section. This will allow you to have more organizational structuring around the storage of various settings. Include a custom section by including the configSections element in the configuration file and a sub-element called section that defines the custom section and the handler for reading it.</span>    <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">When we try to make use of a custom configuration file, under certain circumstance, application throws a System.InvalidcastException.&#160; Below are two such scenarios and the way to get over them.&#160; </span>    <br /><span style="font-size: small; font-family: verdana,geneva; color: #333399"><span style="color: #000000"><span style="font-size: small">As we all know, OpenMappedExeConfiguration gets the custom config file by specifying ExeConfigurationFileMap( with the path of the assembly set) and configuration user level. Here is the MSDN article for reference</span>,</span></span><span style="font-size: small; font-family: verdana,geneva; color: #333399"> <a href="https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedexeconfiguration.aspx">https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedexeconfiguration.aspx</a> </span></p>  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> Public Shared Function Read(ByVal path As String) As DataEnvironmentConfigurationElement</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     Dim section As DataEnvironmentConfigurationSection = DirectCast(DataEnvironment.GetNonDefaultConfigurationFile(path).GetSection(&quot;dataEnvironmentConfiguration&quot;), DataEnvironmentConfigurationSection)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     Return DataEnvironment.GetCurrentEnvironment(section)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> End Function</pre>
<!--CRLF--></div>
</div>

<p><span style="font-size: small; font-family: verdana,geneva">Now, let’s look in to two such scenarios where accessing custom configuration files might lead us to System.InvalidcastException</span></p>

<p>
  <br /><span style="font-size: small; font-family: verdana,geneva"><strong>Scenario 1</strong>: We have a configuration file that tries to access the Section information in the code using GetSection but results in the type cast error while it was accessed. </span>

  <br /><span style="font-size: small; font-family: verdana,geneva">When the type information was checked, everything looked perfect. And the config file being XML format we might think that we can follow any order of elements that are being used in the config file, The faulting config file looked as shown below,&#160; </span>

  <br />

  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
    <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <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></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">appSettings</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">key</span><span style="color: #0000ff">=&quot;Key1&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;value1&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appSettings</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;dataEnvironmentConfiguration&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;CustomConfigurationSample.DataEnvironmentConfigurationSection, CustomConfigurationSample&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>   </pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">dataEnvironmentConfiguration</span> <span style="color: #ff0000">currentDataEnvironment</span><span style="color: #0000ff">=&quot;UT&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">dataEnvironments</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;name1&quot;</span> <span style="color: #ff0000">userName</span><span style="color: #0000ff">=&quot;user1&quot;</span> <span style="color: #ff0000">password</span><span style="color: #0000ff">=&quot;pasword1&quot;</span> <span style="color: #ff0000">collection</span><span style="color: #0000ff">=&quot;new value&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;name2&quot;</span> <span style="color: #ff0000">userName</span><span style="color: #0000ff">=&quot;user2&quot;</span> <span style="color: #ff0000">password</span><span style="color: #0000ff">=&quot;password2s&quot;</span> <span style="color: #ff0000">collection</span><span style="color: #0000ff">=&quot;new value21&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataEnvironments</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataEnvironmentConfiguration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
  </div>
</p>

<p><span style="font-size: small; font-family: verdana,geneva">When we make use of this config file, we will get a System.InvalidcastException. </span>

  <br /><span style="font-size: small; font-family: verdana,geneva">Resolution</span>

  <br /><span style="font-size: small; font-family: verdana,geneva">There is one catch in the above snip which is the root cause of the issue. While DOM (Data Object model) tries to parse the config section, it looks for the type information mentioned in the ConfigSections element, and there is a specific requirement that, this ConfigSections appears just below the Configuration element. CLR XML DOM parser assumes that the configSections element is the first element in the configuration file.</span>

  <br />

  <br /><span style="font-size: small; font-family: verdana,geneva">Here is how it should appear, </span>

  <br />

  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
    <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <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></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;dataEnvironmentConfiguration&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;CustomConfigurationSample.DataEnvironmentConfigurationSection, CustomConfigurationSample&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">configSections</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">appSettings</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">key</span><span style="color: #0000ff">=&quot;Key1&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;value1&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">appSettings</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">dataEnvironmentConfiguration</span> <span style="color: #ff0000">currentDataEnvironment</span><span style="color: #0000ff">=&quot;UT&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">dataEnvironments</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;name1&quot;</span> <span style="color: #ff0000">userName</span><span style="color: #0000ff">=&quot;user1&quot;</span> <span style="color: #ff0000">password</span><span style="color: #0000ff">=&quot;pasword1&quot;</span> <span style="color: #ff0000">collection</span><span style="color: #0000ff">=&quot;new value&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;name2&quot;</span> <span style="color: #ff0000">userName</span><span style="color: #0000ff">=&quot;user2&quot;</span> <span style="color: #ff0000">password</span><span style="color: #0000ff">=&quot;password2s&quot;</span> <span style="color: #ff0000">collection</span><span style="color: #0000ff">=&quot;new value21&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataEnvironments</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">dataEnvironmentConfiguration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
  </div>
</p>

<p><span style="font-size: small; font-family: verdana,geneva">So, when&#160; we the make the necessary changes in the custom config file, the issue gets fixed and we are good to use the config file. You could get more information about this in the MSDN article, <a href="https://msdn.microsoft.com/en-us/library/ms228256.aspx">https://msdn.microsoft.com/en-us/library/ms228256.aspx</a> </span></p>

<p><span style="font-size: small; font-family: verdana,geneva">Well, that was simple. But when we miss the basic element order in the config file it becomes a little difficult to locate the fault. </span>

  <br /><span style="font-size: small; font-family: verdana,geneva">Let’s look at the second&#160; scenario which also throws InvalidtypeCastException, but under different circumstances, </span></p>

<p><span style="font-size: small; font-family: verdana,geneva"><strong>Scenario 2</strong>: Here is another scenario where the application throws InvalidtypeCastException and this time it’s while accessing &lt;Sectiongroups&gt;. Let’s look in to the sample that leads to&#160; the exception, </span>

  <br /><span style="font-size: small; font-family: verdana,geneva">We try to get the section detail of the custom config file, Read( ) function (with the path where we have the custom config as the parameter) does the work for us. </span>

  <br />

  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
    <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Shared</span> <span style="color: #0000ff">Function</span> Read(<span style="color: #0000ff">ByVal</span> path <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>) <span style="color: #0000ff">As</span> DataAccessDefinition</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">Dim</span> c = GetNonDefaultConfigurationFile(path)</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">Return</span> <span style="color: #0000ff">DirectCast</span>(c.GetSection(<span style="color: #006080">&quot;DataAccessDefinition/DataAccess1&quot;</span>), DataAccessDefinition) </pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">End</span> Function</pre>
<!--CRLF--></div>
  </div>
</p>

<p><span style="font-size: small; font-family: verdana,geneva">We get the non-custom config file path by using OpenMappedExeConfiguration of the config file, </span>

  <br />

  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
    <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">Private</span> <span style="color: #0000ff">Shared</span> <span style="color: #0000ff">Function</span> GetNonDefaultConfigurationFile(<span style="color: #0000ff">ByVal</span> path <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>) <span style="color: #0000ff">As</span> Configuration</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">Dim</span> ecfm = <span style="color: #0000ff">New</span> ExeConfigurationFileMap()</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> ecfm.ExeConfigFilename = path</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> <span style="color: #0000ff">Return</span> ConfigurationManager.OpenMappedExeConfiguration(ecfm, ConfigurationUserLevel.None)</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span> <span style="color: #0000ff">End</span> Function</pre>
<!--CRLF--></div>
  </div>
</p>

<p><span style="font-size: small; font-family: verdana,geneva">Handler is implemented as shown below,&#160; </span>

  <br /> 

  <br />

  <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
    <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> DataAccessConfigHandler</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #0000ff">Implements</span> IConfigurationSectionHandler</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>&#160; </pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Function</span> Create(<span style="color: #0000ff">ByVal</span> parent <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span>, <span style="color: #0000ff">ByVal</span> configContext <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span>, <span style="color: #0000ff">ByVal</span> section <span style="color: #0000ff">As</span> System.Xml.XmlNode) <span style="color: #0000ff">As</span> <span style="color: #0000ff">Object</span> <span style="color: #0000ff">Implements</span> System.Configuration.IConfigurationSectionHandler.Create</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>         <span style="color: #0000ff">Dim</span> dataAccess = <span style="color: #0000ff">New</span> DataAccessDefinition</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>         dataAccess.ConnectionName = section.SelectSingleNode(<span style="color: #006080">&quot;connectionName&quot;</span>).InnerText</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>         dataAccess.CommandText = section.SelectSingleNode(<span style="color: #006080">&quot;commandText&quot;</span>).InnerText</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>         dataAccess.CommandType = section.SelectSingleNode(<span style="color: #006080">&quot;commandType&quot;</span>).InnerText</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>         <span style="color: #0000ff">Return</span> dataAccess</pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>     <span style="color: #0000ff">End</span> <span style="color: #0000ff">Function</span></pre>
<!--CRLF-->

      <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Class</span></pre>
<!--CRLF--></div>
  </div>
</p>

<p><span style="font-size: small; font-family: verdana,geneva">While this handler works fine for a default config file, it results in a System.InvalidCastException when we make use of the custom config file. </span>

  <br /><span style="font-size: small; font-family: verdana,geneva">Resolution:</span>

  <br /><span style="font-size: small; font-family: verdana,geneva">As IconfigurationSectionHandler is deprecated</span><span style="font-size: small; font-family: verdana,geneva; color: #333399"> [ref: <a href="https://msdn.microsoft.com/en-us/library/system.configuration.iconfigurationsectionhandler.aspx"><span style="color: #333399">https://msdn.microsoft.com/en-us/library/system.configuration.iconfigurationsectionhandler.aspx</span></a>], </span><span style="font-size: small; font-family: verdana,geneva; color: #333399"><span style="color: #000000">the best way to access the Section group is to follow the following method described below,</span></span>

  <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">The configuration section defines which type is used to de-serialize the XML file, and if you try to cast to an incompatible type you will (as expected) get a casting error.</span>

  <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">I was able to get it working by using the suggested method of deriving from ConfigurationSection as IconfigurationSectionHandler is deprecated.</span>

  <br /><span style="font-size: small; font-family: verdana,geneva; color: #000000">Below is the implementation detail;</span></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">Public</span> <span style="color: #0000ff">Class</span> DataAccessConfigHandler</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>     <span style="color: #0000ff">Inherits</span> ConfigurationSection</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     <span style="color: #0000ff">Public</span> dataAccess <span style="color: #0000ff">As</span> DataAccessDefinition</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">Protected</span> <span style="color: #0000ff">Overrides</span> <span style="color: #0000ff">Sub</span> DeserializeSection(<span style="color: #0000ff">ByVal</span> reader <span style="color: #0000ff">As</span> System.Xml.XmlReader)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060">   7:</span> dataAccess = <span style="color: #0000ff">New</span> DataAccessDefinition</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>&#160; </pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060">   9:</span> <span style="color: #0000ff">While</span> reader.Read()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span> <span style="color: #0000ff">If</span> reader.NodeType &lt;&gt; XmlNodeType.Element <span style="color: #0000ff">Then</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>    Continue <span style="color: #0000ff">While</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060">  13:</span> <span style="color: #0000ff">Select</span> <span style="color: #0000ff">Case</span> reader.Name</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span> <span style="color: #0000ff">Case</span> <span style="color: #006080">&quot;connectionName&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060">  15:</span> dataAccess.ConnectionName = reader.ReadElementContentAsString()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span> <span style="color: #0000ff">Case</span> <span style="color: #006080">&quot;commandText&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060">  17:</span> dataAccess.CommandText = reader.ReadElementContentAsString()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060">  18:</span> <span style="color: #0000ff">Case</span> <span style="color: #006080">&quot;commandType&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060">  19:</span> dataAccess.CommandType = reader.ReadElementContentAsString()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060">  20:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Select</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060">  21:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">While</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060">  22:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060">  23:</span> <span style="color: #0000ff">End</span> <span style="color: #0000ff">Class</span></pre>
<!--CRLF--></div>
</div>

<p><span style="font-size: small; font-family: verdana,geneva; color: #000000">Usage example:</span></p>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">Dim</span> h = <span style="color: #0000ff">DirectCast</span>(ConfigurationManager.GetSection(<span style="color: #006080">&quot;DataAccessDefinition/DataAccess1&quot;</span>), DataAccessConfigHandler)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>         <span style="color: #0000ff">Return</span> h.dataAccess</pre>
<!--CRLF--></div>
</div>

<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">sectionGroup</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;DataAccessDefinition&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">section</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;DataAccess1&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;CustomConfigurationSample.DataAccessConfigHandler,CustomConfigurationSample&quot;</span><span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">sectionGroup</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p><span style="font-size: small; font-family: verdana,geneva; color: #000000">Please refer to the MSDN article for more details,<a href="https://msdn.microsoft.com/en-us/library/2tw134k3.aspx"><span style="color: #000000">https://msdn.microsoft.com/en-us/library/2tw134k3.aspx</span></a>&#160;</span></p>

<p><span style="font-family: verdana,geneva; color: #000000"><span style="font-size: small">&#160;</span><span style="font-size: small">Now this works absolutely fine. Hope this helps while working with configuration files.</span></span></p>

<p>&#160;</p>

<p><span style="font-size: small; font-family: verdana,geneva; color: #000000">Ganesh Shankaran</span></p>

<p><span style="font-size: small; font-family: verdana,geneva; color: #000000">Software Development Engineer</span></p>]]></content:encoded>
    </item>
  </channel>
</rss>