<?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>Azure PaaS</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/karansingh/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/karansingh/feed.xml</link>
    <description>Blog on Azure App Services</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:08:18 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Azure App Service : Automate VNET Re-sync in case of failure</title>
      <link>https://docs.microsoft.com/archive/blogs/karansingh/azure-app-service-automate-vnet-re-sync-in-case-of-failure</link>
      <pubDate>Thu, 04 Jan 2018 20:46:36 GMT</pubDate>
      <dc:creator><![CDATA[Karan.Singh]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/karansingh/?p=215</guid>
      <description><![CDATA[Use Case 
Azure App Service is associated with a Virtual Network using the point-to-site connection...]]></description>
      <content:encoded><![CDATA[<strong><u>Use Case</u></strong><strong> </strong>
Azure App Service is associated with a Virtual Network using the point-to-site connection and accessing resources which are present inside that Virtual Network. Sometimes due to x reason, the Virtual Network connection is getting disconnected and causing downtime in the application. However, the issue can be resolved by re-syncing the VNET.

Now, you want an automated way which can detect this situation and automatically perform a re-sync operation on VNET.
&nbsp;

<strong><u>PowerShell to re-sync VNET</u></strong><strong> </strong>
<script src="https://gist.github.com/karansinghkushwah/6e3f70db4d64222e21dcd0f31a3979a8.js"></script>
&nbsp;

<strong><u>Re-sync VNET using WebJobs</u></strong><strong> </strong>
To perform Sync operation on Virtual Network using WebJobs, you need a way to silently authenticate (Without any login prompt). Please follow the link below for information about silent authentication:
<ul>
 	<li><a href="https://blogs.msdn.microsoft.com/karansingh/2017/10/10/azure-silent-authentication-using-azure-ad-application/">Azure: Silent Authentication using Azure AD application </a></li>
</ul>

Once we have the Service Principal Id, Tenant Id, Subscription Id and Password values using the output of the previous step. Create a scheduled web job and Add PowerShell script which will ping the application URL and will perform VNET re-sync if there is a failure:

<script src="https://gist.github.com/karansinghkushwah/2005a0ea599984f09fe78a4d0afeec53.js"></script>

<strong>Note: </strong>Azure Automation Runbooks can also be used to automate this process. 

<a href="https://docs.microsoft.com/en-us/azure/automation/automation-runbook-types">https://docs.microsoft.com/en-us/azure/automation/automation-runbook-types</a>]]></content:encoded>
    </item>
    <item>
      <title>Azure : Silent Authentication using Azure AD application</title>
      <link>https://docs.microsoft.com/archive/blogs/karansingh/azure-silent-authentication-using-azure-ad-application</link>
      <pubDate>Tue, 10 Oct 2017 20:16:02 GMT</pubDate>
      <dc:creator><![CDATA[Karan.Singh]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/karansingh/?p=205</guid>
      <description><![CDATA[Use Case 

You want to automate management operations on Azure resources using Azure Powershell....]]></description>
      <content:encoded><![CDATA[<strong><u>Use Case</u></strong><strong> </strong>

You want to automate management operations on Azure resources using Azure Powershell. For this, you need a way to silently authentication (Without any login prompt).

You can achieve this by creating an Azure AD application which will give Service Principal Id, which can be used for authentication

&nbsp;

<strong><u>Get Service Principle Id for silent authentication</u></strong><strong> </strong>

Please run below Power-Shell script to create a native AD application from which we will get service principal ID that will be used to do silent authentication.<strong> This is a one time job.</strong>

<strong><u></u></strong><strong><u>Note</u></strong><strong>: </strong>You need to be Global admin on active directory to create the native AD appliction.

<script src="https://gist.github.com/karansinghkushwah/0415e368231d1bbfb94cbd18bd964a24.js"></script>

When you run this script, you will get prompt to provide Subscription Name, Password and then log in.

After completion, you will get below information in output:

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/PsOutput.png" alt="untitled3-1024x509" width="634" height="157" class="size-large wp-image-65 aligncenter" />

<strong><u></u></strong><strong><u>Note</u></strong><strong>: </strong>Please keep a note of th.s information, we'll use it in following steps.

&nbsp;

<strong><u>Login using Service Principal Id without user interaction</u></strong><strong> </strong>
<ul>
 	<li>Create a PowerShell and save as run.ps1</li>
 	<li>Update Service Principal Id, Tenant Id, Subscription Id and Password values using output of previous step.</li>
</ul>
<script src="https://gist.github.com/karansinghkushwah/e1ad25e56b8d4a50cf243beaddb4fc36.js"></script>

<strong><u></u></strong><strong><u>Note</u></strong><strong>: </strong>In above sample, We have shown how to STOP/START an Azure App Service without any user interaction.

After login, you can run any PowerShell script which requires subscription level access without any user interaction.

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Azure App Services: How to determine if the client certificate is loaded</title>
      <link>https://docs.microsoft.com/archive/blogs/karansingh/azure-app-services-how-to-determine-if-the-client-certificate-is-loaded</link>
      <pubDate>Wed, 15 Mar 2017 17:50:01 GMT</pubDate>
      <dc:creator><![CDATA[Karan.Singh]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/karansingh/?p=115</guid>
      <description><![CDATA[USE CASE

Application is hosted on Azure App Service and it requires the use of client...]]></description>
      <content:encoded><![CDATA[<strong><u>USE CASE</u></strong>

Application is hosted on Azure App Service and it requires the use of client certificate, you can upload your certificate to the certificates collection in Azure App Service and consume it in your web application from your site’s personal certificate store. This functionality is only available for dedicated sites (Basic, Standard, Premium pricing tiers).

You can follow the steps/code mentions in below article to implement this in C# application:
<ul>
 	<li><a href="https://azure.microsoft.com/en-in/blog/using-certificates-in-azure-websites-applications/">https://azure.microsoft.com/en-in/blog/using-certificates-in-azure-websites-applications/</a></li>
 	<li><a href="https://channel9.msdn.com/blogs/Azure-App-Service-Self-Help/Upload-an-SSL-Certificate">https://channel9.msdn.com/blogs/Azure-App-Service-Self-Help/Upload-an-SSL-Certificate</a></li>
</ul>
&nbsp;

<strong><u>ISSUE DEFINITION</u></strong>

The same code was running fine but suddenly application started throwing exception while loading the client certificates from cert store.

&nbsp;

<span style="text-decoration: underline"><strong>CHECK IF CERTIFICATE IS LOADING OR NOT?</strong></span>

<span style="text-decoration: underline"><b><i>Using Power Shell</i></b></span>
<ol>
 	<li>Check for the application setting and see if <strong>WEBSITE_LOAD_CERTIFICATES</strong> is present or not. (This is required to load the client certificates for application)</li>
</ol>
<img width="803" height="158" class="size-full wp-image-116 aligncenter" alt="1" src="https://msdnshared.blob.core.windows.net/media/2017/03/12.jpg" />
<ol start="2">
 	<li>Open Azure Portal, go to <strong>Advance tools</strong>-&gt; Click on <strong>Go</strong></li>
 	<li>Select <strong>Debug console</strong>-&gt; <strong>PowerShell</strong></li>
 	<li>Run command “<strong>cd cert:\currentuser\my</strong>”</li>
 	<li>Run command “<strong>dir</strong>”</li>
 	<li>It should list down all the certificates loaded for this application. (Note: Please make sure that application setting <strong>WEBSITE_LOAD_CERTIFICATES</strong> is present)</li>
</ol>
<img width="823" height="606" class="size-full wp-image-125 aligncenter" alt="2" src="https://msdnshared.blob.core.windows.net/media/2017/03/22.jpg" />

<strong><u>Note:</u></strong> If your site is running on multiple instances, than you should run above PowerShell command on all the instances. Please follow below link for more information on how to connect to the Kudu site of specific instance:
<ul>
 	<li><a href="https://blogs.msdn.microsoft.com/kaushal/2016/11/21/azure-app-service-how-to-connect-to-the-kudu-site-of-a-specific-instance/">https://blogs.msdn.microsoft.com/kaushal/2016/11/21/azure-app-service-how-to-connect-to-the-kudu-site-of-a-specific-instance/</a></li>
</ul>
&nbsp;

<span style="text-decoration: underline"><b><i>Using Site Extension</i></b></span>

You can install <strong>Certificate Read Checker(CRC)</strong> <a href="https://www.siteextensions.net/packages/CertificateReadChecker/">Web Site Extension</a>. Using this extension one can easily test whether uploaded certificate can be read via code or not.

The site extension is already present in the Site Extension gallery.

<strong><u></u></strong>

&nbsp;

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Azure App Services: Automate Application restart using Web Job</title>
      <link>https://docs.microsoft.com/archive/blogs/karansingh/azure-app-services-automate-application-restart-using-web-job</link>
      <pubDate>Fri, 10 Feb 2017 06:59:42 GMT</pubDate>
      <dc:creator><![CDATA[Karan.Singh]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/karansingh/?p=25</guid>
      <description><![CDATA[Use Case 

An application is hosted on Azure as App Service and you want to restart your...]]></description>
      <content:encoded><![CDATA[<strong><u>Use Case</u></strong><strong> </strong>

An application is hosted on Azure as App Service and you want to restart your application on a scheduled basis.

You can achieve this by creating a web job and placing a PowerShell script to STOP and START the web app. Please follow the steps below to implement this for your web app:

&nbsp;

<strong><u>Get Service Principle Id for silent authentication</u></strong><strong> </strong>

To perform START/STOP operation on Azure App Service, the job should have access to your subscription. Please run below Power-Shell script to create a native AD application from which we will get service principal ID that will be used to do silent authentication.<strong> This is a one time job.</strong>

<strong><u></u></strong><strong><u>Note</u></strong><strong>: </strong>You need to be a Global admin on Active Directory to create the native AD application.

<script src="https://gist.github.com/karansinghkushwah/0415e368231d1bbfb94cbd18bd964a24.js"></script>

When you run this script, you will get prompt to provide Subscription Name, Password and then log in.

After completion, you will get information in output:

<img src="https://msdnshared.blob.core.windows.net/media/2017/02/PsOutput.png" alt="untitled3-1024x509" width="634" height="157" class="size-large wp-image-65 aligncenter" />

<strong><u></u></strong><strong><u>Note</u></strong><strong>: </strong>Please keep a note of this information, we'll use it in following steps.

&nbsp;

<strong><u>Create PowerShell to STOP/START App Service</u></strong><strong> </strong>
<ul>
 	<li>Create a PowerShell and save as run.ps1</li>
 	<li>Update Service Principal Id, Tenant Id, Subscription Id and Password values using the output of the previous step.</li>
</ul>
<script src="https://gist.github.com/karansinghkushwah/e1ad25e56b8d4a50cf243beaddb4fc36.js"></script>

&nbsp;

If the application is running on multiple instances, then you can use below script to leverage <strong>Advanced Application restart</strong>. In this case below script will restart worker process on each instance one by one. This can help in minimizing the downtime.

<script src="https://gist.github.com/karansinghkushwah/9c61121637ea05ce68c7d38ee27cf192.js"></script>

&nbsp;

<strong><u>Create a scheduled web job</u></strong><strong> </strong>
<ul>
 	<li>Create a zip file which contains both the files (<strong>ps1</strong> and <strong>azureprofile.json</strong>).</li>
 	<li>Go to App Service -&gt; Web Job and then create a triggered web job by uploading the zip file.</li>
</ul>
<img src="https://msdnshared.blob.core.windows.net/media/2017/02/Untitled3-1024x5091-1024x509.png" alt="untitled3-1024x509" width="1024" height="509" class="size-large wp-image-65 aligncenter" />
<ul>
 	<li>Make sure that <strong>Always on</strong> is enabled on the App Service where you are deploying this web job. <strong>Always on</strong> is required for triggered web jobs.</li>
</ul>
&nbsp;

<strong><u>Note</u></strong>: Please follow the link below for information about scheduling web job using CRON expression:
<ul>
 	<li><a href="https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-create-web-jobs">https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-create-web-jobs </a></li>
</ul>
&nbsp;]]></content:encoded>
    </item>
  </channel>
</rss>