Thursday, January 16, 2020

how to quickly setup a swagger in asp.net core Web API project with visual studio

1. Create a ASP.Net web project with Visual studio

2. Install the Swagger package in the Package Manager window

              Install-Package Swashbuckle.AspNetCore

 3. add swagger generator to services collection which is the dependency injection container

        services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
            });

4. setup the swagger in the configure method
         // enable the swagger middleware
           app.UseSwagger();

            // Enable middleware to serve swagger-ui
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

5. launch the app and view the swagger ui from the link below, please note the port will be different

  https://localhost:{port}/swagger/index.html

   for my local development i had the following

     https://localhost:44392/swagger/index.html



Tuesday, January 14, 2020

Interview Question 1.

I am actively looking for new opportunties now. i will keep posting the interview question that had been asked in each interview. i hope you can learn from the interview questions.

1.if the element is not found, but it showed in the inspector what reason


A: the function had been called, before the DOM is ready

1.how to generate a token in .net?

2. can two same class in the stylesheet.

3. what is cause that style border is black, but show red in the browser?

4. how to trouble the slow sql dynamic query?

5. how do you do the eblast for marketing?

6. how do you send a link to a customer, that will automatically redirect to the customer account?

7. SQL injection

8. customerError in web config file, how do you enable the error message with customError="RemoteOnly"?

9. static variable vs normal variable

A: static variable can be access with instantiate the class, out of class scope if the access modifier is public
normal variable can not be access without instantiate the class.


Friday, January 10, 2020

A new tool App Service Editor is currently under preview in Azure Portal

I just found a new feature in the Azure Portal today. it is a web based tool for Azure Web App in the Development Tool section of App Service.












after you click on the App Service Editor item. it will popup a new page.









if you want to learn more information about this new tool, please check on the link below

Understanding the Azure App Service Editor

How to troubleshoot the sync failed issue in DevOps deployment?

After i push the change from local to Github, then i click on the sync button in the deployment center.






How the status indicated that the sync result is failed. we can check the issue by click on the Log button to expand the log section.











Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\DanCoreWebApp\DanCoreWebApp.csproj]
D:\Program Files (x86)\dotnet\sdk\2.2.109\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\home\site\repository\WebApp2\WebApp2.csproj]
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\DanCoreWebApp.sln"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\85.11214.4277\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

the error log showed that .Net Core version issue. Currently Azure does not support the .Net Core 3.0 in the production.





Sunday, January 5, 2020

Angular Development Quick Tip 1

1. Augury is the great chrome add in to visualize data for Angular Development

you can give it here

https://chrome.google.com/webstore/detail/augury/elgalmkoelokbchhkhacckoklkejnhcd/related?hl=en










2. run ng generate command with -d flag to verify the location, name etc before it really create them.
 since dry run mode will not make any change in the current solution

ng generate service myService -d








C:\DanAngular\dan-app>ng generate service myService -d
CREATE src/app/my-service.service.spec.ts (349 bytes)
CREATE src/app/my-service.service.ts (138 bytes)

NOTE: The "dryRun" flag means no changes were made.

from the above output, I should be able to find that i do not need to use myService as the service name

i tweak my command to ng generate serivce my -d








C:\DanAngular\dan-app>ng generate service my -d
CREATE src/app/my.service.spec.ts (313 bytes)
CREATE src/app/my.service.ts (131 bytes)

NOTE: The "dryRun" flag means no changes were made.





Thursday, January 2, 2020

Handy Tool to Manipulate JSON Data

1. Andrew Friedman create an online tool to convert C# data object to JSON format Data.

it will really help in generate JSON data to Test Web API

https://csharp2json.io/

2. Jonathan Keith launched a web site for converting JSON Data to C# Class

it will reduce the time to code the Business Object for Web API consumption. Since we can get the sample JSON Data from web api portal or web api swagger. we just have to copy the sample JSON data and paste input the textbox, then click generate.

we can copy the output and add them to your project. it can save time and avoid the typo error.

http://json2csharp.com/




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 ...........................