Giter VIP home page Giter VIP logo

aspnet-identity-2-with-integer-keys's Introduction

AspNet-Identity-2-With-Integer-Keys

This project approches a little more advanced customization of the ASP.NET Identity 2.0 RTM framework. The project accompannies a blog post which walks through the basics of implementing integer keys instead of the default string keys which Identity uses out-of-the-box. The project starts with the Identity Samples project available from Nuget.

The post which accompanies this example can be found at ASP.NET Identity 2.0 Extending Identity Models and Using Integer Keys Instead of Strings

If you find errors, or have suggestions for improvement, please feel free to open an issue, and/or submit a pull request.

aspnet-identity-2-with-integer-keys's People

Contributors

xivsolutions avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnet-identity-2-with-integer-keys's Issues

CreateDatabaseIfNotExists Initializer

I am trying to get the database to be created ONLY if it does not exist but am not being successful. I only replaced DropCreateDatabaseAlways() and replaced it with CreateDatabaseIfNotExists(). Do you think that is all I have to do?

Here is what my ApplicationDbInitializer() now looks like:

public class ApplicationDbInitializer : CreateDatabaseIfNotExists<ApplicationDbContext>
{
    protected override void Seed(ApplicationDbContext context)
    {
        InitializeIdentityForEF(context);
        base.Seed(context);
    }

    //Create [email protected] with password=Admin@123456 in the Admin role        
    public static void InitializeIdentityForEF(ApplicationDbContext db)
    {
        var userManager = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
        var roleManager = HttpContext.Current.GetOwinContext().Get<ApplicationRoleManager>();
        const string name = "[email protected]";
        const string password = "Admin@123456";
        const string roleName = "Admin";

        //Create Role Admin if it does not exist
        var role = roleManager.FindByName(roleName);
        if (role == null)
        {
            role = new ApplicationRole(roleName);
            var roleresult = roleManager.Create(role);
        }

        var user = userManager.FindByName(name);
        if (user == null)
        {
            user = new ApplicationUser { UserName = name, Email = name };
            var result = userManager.Create(user, password);
            result = userManager.SetLockoutEnabled(user.Id, false);
        }

        // Add user admin to Role Admin if not already added
        var rolesForUser = userManager.GetRoles(user.Id);
        if (!rolesForUser.Contains(role.Name))
        {
            var result = userManager.AddToRole(user.Id, role.Name);
        }
    }
}

Use Guid Instead of Integer

First of all, thank you for your tutorial on your site and the example code. I am a lover of extremely long identifiers and thought I would try my hand at using Guid as the type for the key (since you were able to use the extension method to use int, I thought it should be as simple as a find/replace, but it would seem it is not. Have you tried this and if so, how were you able to get around the issue:

image

Input string was not in a correct format

Hi John,

Received the following error in IdentitySample.Startup.ConfigureAuth at the app.UseCookieAuthentication call on line 25.

It is on a brand new build, no database setup yet.

{System.FormatException: Input string was not in a correct format
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at IdentitySample.Startup.b__3(ClaimsIdentity claim) in c:\Users\Riaan\Documents\Visual Studio 2013\Samples\AspNetIdentity2IntegerKeys\IdentitySample\App_Start\Startup.Auth.cs:line 37
at Microsoft.AspNet.Identity.Owin.SecurityStampValidator.<>c__DisplayClass2`3.<b__1>d__4.MoveNext()}

Web output:

Line 35: regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
Line 36: // Need to add THIS line because we added the third type argument (int) above:
Line 37: getUserIdCallback: (claim) => int.Parse(claim.GetUserId()))
Line 38: }
Line 39: });

Any suggestions?

Small Error in AccountController ConfirmEmail

I think the logic for ConfirmEmail got messed up when changing the null check of string to a > 0 check for an int.

It should be something like:

if(userId > 0 && code != null){
//Do success stuff
}
//Do Error stuff

Compiler Error Message: CS0234

Compiler Error Message: CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?).

Fixed by cleaning the project, going to References, Properties of the System.web.mvc and setting copy local true.

NuGet Packages not included

When I open this project in VS2013 SP3 most of the references are not available. This appears to be because you have used NuGet to download the references. How can I fix this problem easily?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.