Sunday, June 20, 2021

How to host an ASP.Net Core Web API in IIS?

 during our development of ASP.Net Web API on visual studio. there is an embedded IIS express with visual studio.

if we want to host the web api in our local IIS. we can follow these steps.


finally my web api application that hosted on IIS is up and running




how to fix the website loading forever in local IIS for windows 10?

 Recently i setup a local IIS for my web api development. however i can complete the configuration, then try to browse the website from browser. it is loading forever and the web page never loaded.

the main cause of the issue is the idle time-out(minutes) had been set to 20 by default.

after I change it to 0 and recycle the app pool, then the website is working and page is loaded.








 

cheer and happy programming



SOLID development principles in brief explanation

 solid development principles is a very popular development methodology. we might encounter an interview question about what is SOLID.

since we usually have less time to prepare for tons of interview question. I try to describes five principles in short.

S: Single Responsibility Principle

Object should only have single single responsibility. best example database persistence vs file persistence

we should not bundle them together.

O: Open and Close Principle

Object is open for extension, but not for modification. for any new enhancement or new feature, we should keep the current interface intact. and extend a new interface base on the current one.

L: Liskov Substitution Principle

the interface take the type of parent, should not break if it takes the type of its child.

I : Interface Segregation Principle

split the interface for each individual client, better than have one generous interface for all. it is better and easy for maintenance.

D: Dependency Inversion Principle

  • High level of object never depends on the low level of object.
  • Abstractions should not depend on details, but details should depend on abstraction.



Saturday, June 19, 2021

how to use hashtable to quickly find the sum of two numbers meet the criteria?

 if there is a number array, we want to find the indexs of two numbers adding together meet the give number.

for an example we have a number array {1, 3,  4,  5, 8} and given 8

the result should be 1 , 3


where is sample code to solve the above issue.

using System;

using System.Collections;

using System.Diagnostics.CodeAnalysis;


namespace hashmap

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Hello World!");


            int[] numarray = new int[7] { 1, 2, 3, 4 ,5, 6, 8};

            int[] resultArray = new int[2];

            int testNum = 7;

            Hashtable ht = new Hashtable();

            for (int i = 0; i < numarray.Length; i++) {

                int result = 7 - numarray[i];

                if (ht.ContainsKey(numarray[i]))

                {

                    resultArray[0] = i;

                    resultArray[1] = (int)ht[numarray[i]];

                }

                else {

                    ht.Add(result, i);

                }

            }

            Console.WriteLine("position at {0}  {1}", resultArray[0], resultArray[1]);

        }

    }

}


Wednesday, May 5, 2021

how to fix Compiler option noEmitOnError not working with tsc in Typescript?

it is the best practice to use "noEmitOnError" option to prevent typescript compiler to generate the JavaScript file

however the config setting file does not work, when we execute the compiler command. such as the following

tsc myfile.ts 

the output is myfile.js. obviously the compiler did not pick the configuration from the config file. we have to run it expressively 

tsc --noEmitOnError myfile.ts

or force the compile to read from the tsconfig.json file

tsc -p ./tsconfig.json


Sunday, April 11, 2021

how to access Azure Active Directory from other portals?

 we should all know that we can use Azure portal to access the Azure Active directory. after you log into the portal we can click on the Azure Active Directory from the left blade, or type " Azure Active Directory " in the search box to access Azure Active Directory features

However Microsoft also provide tow alternative ways to access the Azure Active Directory with same login credential as we use for azure portal.

here are the two web portals we can use to access Azure Directory.

https://admin.microsoft.com

https://myapps.microsoft.com 

Sunday, March 14, 2021

how to fix "The files of the specified task cannot be accessed as the task state is still active" in az batch task file command execution?

when we run the az batch task file list to show all the task file in batch execution. we encounter the following error immediately.

 " The specified operation is not valid for the current state of the resource.
RequestId:bfad4b09-53a4-4a7f-b9a5-d54a630699d7
Time:2021-03-14T17:17:42.8558070Z
Reason: The files of the specified task cannot be accessed as the task state is still active"

afterwe try to az batch task file download, we got the same error.

actually we can solve this issue by requesting dedicated nodes manually on the portal for that specific batch account.

 here are the steps to reach our goal.

 1. go the batch account

 


 

 

 

  

2. click on the pools item on the blade to show the pools under this batch account


 

 

 

 

 3. click on the pool name that we created for batch action.


 

 

 

 

4.click on the nodes item on the blade.

 

 






5.click on the any node under the name column to view the contents in the node





6.click on the workitems folder to view the batch  job which is myjob that we created previously


7.click on myjob folder, then click on myjob1, and click on the task1 to show the content of task1.







8. click on the stardout.txt to show the task execution result.





now we can verify our batch process manually in the azure portal.