Saturday, November 16, 2019

Azure Quick tips

1. how to go to the specific folder and list items inside the folder in Azure PowerShell ?

 cd ~/yourfolderPath

 the type ls to show the list content






2. How to access Kudu Console for API or web site host in Azure?

I have a sample api URL

https://danfuncappapi.azurewebsites.net/



we can access the Kudue console by adding .scm after the api name

https://danfuncappapi.SCM.azurewebsites.net/


here is the Kudu Console for my sample API








3. We can use the Microsoft azure storage explorer to visualize the content in the azure

you can download a copy of the Azure storage explorer from the link below

https://azure.microsoft.com/en-us/features/storage-explorer/

here is the screen shot of the content under my azure account.




















4. How to check the Package version from Azure PowerShell window?

type pip3 freeze  will show you the list of package with version number in the powershell window















5. how to launch a Code Editor within Azure CLI windows

it is simple and straight. exactly like launching visual studio code in windows CMD

type Code . then the code editor will be shown
















To be continue ...........................

Wednesday, June 19, 2019

how to use MVC razer page as Email Template in ASP.Net MVC application?

it is quite useful for code reuse when we implemented the MVC web application. especially we need to support both English and French Template.


we can lay out the template in English and French.

then we can use Razor Engine to load the specific cshtml page by language code

using RazorEngine;
using RazorEngine.Templating;

the following code will utilize the cache mechanism built in the razor engine for better performance.


  var tmplKey =fileNamebyLanuageCode
            if (!Engine.Razor.IsTemplateCached(tmplKey, null))
            {
                var template = GetEmailTemplate(templateName, language);
                Engine.Razor.AddTemplate(tmplKey, template);
                Engine.Razor.Compile(tmplKey, null);
            }

            return Engine.Razor.Run(tmplKey, null, modelData);



  private static string GetEmailTemplate(string templateName, string language)
        {
          
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(templateName))
            {
                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
        }

Tuesday, June 18, 2019

how to integrate Microsoft Azure Authetication in angular SPA with adal.js?

it is very common to use Azure authentication to authenticate the user access in the SPA.

it is not hard to setup a sample app running if we follow the steps below.

1. install anulgar/CLI

    npm i @angular/CLI 


2. install angular-adal

    npm i angular-adal

3 . install type definition of adal

    npm i @type/adal --save

4. install type script libary

    npm i tslib

5. finally install the microsoft-adal-angular6 package

    npm i microsoft-adal-angular6 
 
6. now you can following the example from this link

https://www.npmjs.com/package/microsoft-adal-angular6


@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
MsAdalAngular6Module.forRoot({
tenant: 'tennat guid id from azure active directory',
clientId: 'the app id registered in the cloud',
// redirectUri: window.location.origin,
// endpoints: {
// "https://localhost/Api/": "xxx-bae6-4760-b434-xxx"
// },
navigateToLoginRequestUrl: false,
cacheLocation: 'localStorage',
})
],
providers: [AuthenticationGuard],
bootstrap: [AppComponent]
})


here is the screen shot showing the path to get the Tenant ID
 
 

  
you can find your app client ID from this image
 
 



actually we can find both tenant ID and client ID after you click on the MyADAuthApp 
in the app registrations section.
 
 
 
 
 
 now we can launch the SPA with ng-serve to run the app, and type http://localhost:4200
 
 it will direct to the azure authentication login screen