Monday, May 28, 2018

Git Commands

To revert local check in. 
git reset Head~1

To view the changes recently reset, 
git reflog show HEAD
or 
git reflog.

This will show you your recent resets and other history.
You can restore it again using following command.
git reset --hard <commit hash>

above command will destroy any local modifiction so better stash them.


To merge your development branch into master.  

1. Check out the branch. 

git checkout development

2.Merge your changes from master into development. (This step is necessary so that you can resolve any merge conflict locally in your development branch. )

git merge development

3.  Check out the master branch now. 

git checkout master

4. Merge the development branch into master. (Make sure to use --no-ff to persist your history.)

git merge --no-ff development. 

5. Push your changes to the master. 




Thursday, May 10, 2018

Getting all Users from AAD using Power Shell and Delete

Connect-MsolService
Get-MsolUser
#get the user principle name.
Connect-AzureAD
Remove-AzureADUser -ObjectId "xxxx.onmicrosoft.com#EXT#@yyyy.onmicrosoft.com"

UPN of the external accounts is as shown above. 

Thursday, May 3, 2018

Storing secrets using SecretManager for development in ASP.NET Core

The purpose of using this is to keep the secured values outside of the code to avoid check in by mistake.

- Modify the .csproj file and add following "Microsoft.Extensions.SecretManager.Tools"

- Save and close.
- Right click the project and select "Manage User Secrets"
- this will open JS. store your secret values in there.  This json file is stored away from the project on local machine.
- Add following into your Startup.cs file.

if (_hostingEnvironment.IsDevelopment())
            {
                builder.AddUserSecrets<Startup>();
            }

- read the secret using Configuration. like if the secret name is "MySecret", read it like Configuration["MySecret"]
-This should only be used in development.
- For production, code will read the value from appsettings.json. 

Routing Trace to Console

ConsoleTraceListener listener = new ConsoleTraceListener();
Trace.Listeners.Add(listener);

Trace.WriteLine("Trace Logs");

Trace.Listeners.Remove(listener);

Trace.Close();