Extend available properties of User.Identity – Asp.Net [web api]

Asp.net web api by default contains some pre configured fields that can handle the registration of a user in a web app. Some of them are Email, Password, Confirm Password and others. You can extend those properties and include your own for your purposes with the following procedure.

First of all you need to execute some commands in the package manager. You can find nuget package manager in Tools -> Nuget Package Manager -> PM Console 

The first thing to do is to enable Migrations

Enable-Migrations

The you can go to Models\AccountBindingModels.cs and add your property to the class RegisterBindingModel. Also add the same property in the Models\IdentityModels.cs inside ApplicationUser class. For example lets assume you want to add a username in the registration proccess. For this purpose you can use the following line

 public string AppUserName { get; set; }

Also include in the file.

using System;

The you must execute:

Add-Migration "AppUserName"
Update-Database

Those commands will run all the migration files and update the database schema to add a AppUserName column in your database.

Then update the registration action in Controllers\AccountController.cs to store AppUserName as well.

var user = new ApplicationUser() { UserName = model.Email, Email = model.Email, AppUserName = model.AppUserName };

It was that easy. you can finally find AppUserName in your database.

Display Herocard in BotFramework

As the botframework evovles, many things are changing in the apis. I wanted to create a Herocard for a bot and the previously existed method wasn’t working, so i find the new way that one can reply herocards in the user. The main function needed is the

context.MakeMessage()

 

Full C# example

 List <CardAction> list = new List<CardAction>();
            list.Add(new CardAction {Title="help", Type=ActionTypes.ImBack, Value="help" });
            list.Add(new CardAction {Title = "commands", Type = ActionTypes.ImBack, Value = "commands" });
            HeroCard hero = new HeroCard();
            hero.Title = "Hero title";
            hero.Text = "Hero text";
            hero.Buttons = list;

            var msg = context.MakeMessage();
            msg.Attachments.Add(hero.ToAttachment());
            await context.PostAsync(msg);

 

The result will look like that

 

This github repo is very useful as it includes many botframework samples.

Query Azure Easy Tables with Postman

There is an easy way to interact with Easy Tables on Azure when you want to test things.

 

You can use a program like postman and create a post request for your table. For example if your table is named users, you should use users after tables/

http://YOURURL.azurewebsites.net/tables/users

 

 

I was testing some requests and I was dealing an exception and I figured that the request should contain the following things.

In the headers is necessary to add Content-Type and Zumo-Api-Version.

 

 

After that you should easily send your post request by selecting raw in the body section.