locked
Owin UserInfo RRS feed

  • Question

  • User-168965715 posted

    What is the best practice to store userinfo in Owin?  SimpleMembership creates UserInfo table.  What is its equivalent in Owin?

    Monday, March 31, 2014 8:24 PM

Answers

  • User1140095199 posted

    Hi,

    What is the best practice to store userinfo in Owin?  SimpleMembership creates UserInfo table.  What is its equivalent in Owin?

    Owin states specification for how  Web frameworks and Web servers interact.

    Owin is Middle ware it cannot be compared with Simple Membership. Owin uses Asp.NET Identity which replaces SimpleMembership. It uses EF and SQL Database to store Use Info.

    Inspired by the benefits achieved by Rack   in the Ruby community, several members of the .NET community set out to create an  abstraction between Web servers and framework components. Two design goals for the  OWIN abstraction were that it was simple and that it took the fewest possible dependencies  on other framework types. These two goals help ensure:

    •  New components could be more easily developed and consumed.
    • Applications could be more easily ported between hosts and potentially entire platforms/operating systems.

    The design has several implications for developers:

    • There are a very small number of type dependencies required in order to write OWIN components. This greatly increases the accessibility of OWIN to developers.
    • The asynchronous design enables the abstraction to be efficient with its handling of computing resources, particularly in more I/O intensive operations.
    • Because the application delegate is an atomic unit of execution and because the environment dictionary is carried as a parameter on the delegate, OWIN components can be easily chained together to create complex HTTP processing pipelines.

    For more reference - http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana

    Use ASP.NET Identity for authentication -http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity

    Identity will use EF by default and create tables to store info.

    Use EF (Entity Framework) to Store Use Info.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 2, 2014 1:29 AM
  • User1140095199 posted

    Hi,

    Then, how do most developers store user information in Owin?  Is it best practice to create a custom table?

    For User normal user info it will be automatically stored in the table. For any excess User info in Membership too you need to create Custom Tables and link them using Profile.

    Storing Additional User Information (C#) in Membership - http://www.asp.net/web-forms/tutorials/security/membership/storing-additional-user-information-cs

    You will need to create custom tables in Membership, SimpleMembership and Identity all if you want to store additional userinfo. Default User info will be managed and stored using EF and default connection into a Local DB . Take a look at the latest templates in ASP.NET. Create User and check. I hope you can get a better idea. Owin as I suggested in my previous Post has nothing to do how you want to store user info.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 3, 2014 12:56 AM
  • User-168965715 posted

    Enough with the theories.  I figured this out and it is very simple.  I will do my best not to appear like a brilliant MIT professor which I am not.

    • Intialize database on application start in the Global.asax file to allow to add columns to Owin tables.  Please note: Owin tables must exist for this line of code to work:
            Database.SetInitializer<ApplicationDbContext>(null);
    • Add new columns to an Owin table in my case one of the columns I added is FirstName to the AspNetUsers table.
    • Add new properties to the RegisterViewModel class and the names must match the column names added to the database table like below:
            [Required]
            [Display(Name = "First Name")]
            public string FirstName { get; set; }
    • Add new properties to the ApplicationUser class again names must match the column names added to the database table like below:
            public string FirstName { get; set; }
    • Now the properties are part of the RegisterViewModel and ApplicationUser classes.  With this, in the Account controller in the HttpPost Register function add the new columns to ApplicationUser like below:
            public async Task<ActionResult> Register(RegisterViewModel model)
            {
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser() { UserName = model.UserName, FirstName = model.FirstName };
    • Offcourse add new fields with the new column names to the Register view.
    • Finally user information is stored. to the database
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2014 12:27 AM

All replies

  • User1140095199 posted

    Hi,

    What is the best practice to store userinfo in Owin?  SimpleMembership creates UserInfo table.  What is its equivalent in Owin?

    Owin states specification for how  Web frameworks and Web servers interact.

    Owin is Middle ware it cannot be compared with Simple Membership. Owin uses Asp.NET Identity which replaces SimpleMembership. It uses EF and SQL Database to store Use Info.

    Inspired by the benefits achieved by Rack   in the Ruby community, several members of the .NET community set out to create an  abstraction between Web servers and framework components. Two design goals for the  OWIN abstraction were that it was simple and that it took the fewest possible dependencies  on other framework types. These two goals help ensure:

    •  New components could be more easily developed and consumed.
    • Applications could be more easily ported between hosts and potentially entire platforms/operating systems.

    The design has several implications for developers:

    • There are a very small number of type dependencies required in order to write OWIN components. This greatly increases the accessibility of OWIN to developers.
    • The asynchronous design enables the abstraction to be efficient with its handling of computing resources, particularly in more I/O intensive operations.
    • Because the application delegate is an atomic unit of execution and because the environment dictionary is carried as a parameter on the delegate, OWIN components can be easily chained together to create complex HTTP processing pipelines.

    For more reference - http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana

    Use ASP.NET Identity for authentication -http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity

    Identity will use EF by default and create tables to store info.

    Use EF (Entity Framework) to Store Use Info.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 2, 2014 1:29 AM
  • User-168965715 posted

    Then, how do most developers store user information in Owin?  Is it best practice to create a custom table?

    Wednesday, April 2, 2014 10:31 PM
  • User1140095199 posted

    Hi,

    Then, how do most developers store user information in Owin?  Is it best practice to create a custom table?

    For User normal user info it will be automatically stored in the table. For any excess User info in Membership too you need to create Custom Tables and link them using Profile.

    Storing Additional User Information (C#) in Membership - http://www.asp.net/web-forms/tutorials/security/membership/storing-additional-user-information-cs

    You will need to create custom tables in Membership, SimpleMembership and Identity all if you want to store additional userinfo. Default User info will be managed and stored using EF and default connection into a Local DB . Take a look at the latest templates in ASP.NET. Create User and check. I hope you can get a better idea. Owin as I suggested in my previous Post has nothing to do how you want to store user info.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 3, 2014 12:56 AM
  • User-168965715 posted

    Enough with the theories.  I figured this out and it is very simple.  I will do my best not to appear like a brilliant MIT professor which I am not.

    • Intialize database on application start in the Global.asax file to allow to add columns to Owin tables.  Please note: Owin tables must exist for this line of code to work:
            Database.SetInitializer<ApplicationDbContext>(null);
    • Add new columns to an Owin table in my case one of the columns I added is FirstName to the AspNetUsers table.
    • Add new properties to the RegisterViewModel class and the names must match the column names added to the database table like below:
            [Required]
            [Display(Name = "First Name")]
            public string FirstName { get; set; }
    • Add new properties to the ApplicationUser class again names must match the column names added to the database table like below:
            public string FirstName { get; set; }
    • Now the properties are part of the RegisterViewModel and ApplicationUser classes.  With this, in the Account controller in the HttpPost Register function add the new columns to ApplicationUser like below:
            public async Task<ActionResult> Register(RegisterViewModel model)
            {
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser() { UserName = model.UserName, FirstName = model.FirstName };
    • Offcourse add new fields with the new column names to the Register view.
    • Finally user information is stored. to the database
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2014 12:27 AM