Asp.net Identity 2.0 作弊条

摘要:
移动ASP.NETIdentitymodeltoclasslibraryhttp://stackoverflow.com/questions/23446919/moving-asp-net-identity-model-to-class-libraryTomovetheIdentityModelintoaclasslibrary(这是正确的记录

Moving ASP.NET Identity model to class library

http://stackoverflow.com/questions/23446919/moving-asp-net-identity-model-to-class-library

To move the IdentityModel into a class library (which is the right thing to do according to the SRP), follow these steps:

  1. Create a class library. (ClassLibrary1)
  2. Using NuGet, add a reference to Microsoft.AspNet.Identity.EntityFramework. This will also auto-add some other references.
  3. Add a reference in your website to ClassLibrary1
  4. Find WebSite/Models/IdentityModel.cs and move it to ClassLibrary1.
  5. Make IdentityModel.cs look like this:

    public class ApplicationUser : IdentityUser
    {
    }
    
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("YourContextName")
        {
        }
    }
  6. Make sure your website's Web.config has YourContextName pointing to the right database in the section. (Note: this database can and should house your application data).

    <add name="YourContextName" connectionString="YourConnectionStringGoesHere"
      providerName="System.Data.SqlClient" />
  7. Make your EF Context class inherit from your ApplicationDbContext:

    public class YourContextName : ApplicationDbContext
    {
        public DbSet<ABizClass1> BizClass1 { get; set; }
        public DbSet<ABizClass2> BizClass2 { get; set; }
        // And so forth ...
    }

When anyone in your site tries to log in or register, the Identity system will route them to your database with all your data which includes the Identity tables.

 

Use Username instead of Email for identity

http://stackoverflow.com/questions/27501533/use-username-instead-of-email-for-identity-in-asp-net-mvc5

In case anyone else gets here from a google search it is actually very easy to do this. If you look at the register post action it is simply setting the UserName to the Email address. So.........

Add UserName to the RegisterViewModel and add it to the register view.

<div class="form-group">
        @Html.LabelFor(m => m.UserName, new { @  })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder = "Username or email" })
        </div>
</div>

In the Register Post Action on the AccountController set the UserName to the ViewModel's UserName and the Email to the ViewModel's Email.

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

Change AspNet Identity table names 

http://stackoverflow.com/questions/19460386/how-can-i-change-the-table-names-when-using-visual-studio-2013-aspnet-identity

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder); // This needs to go before the other rules!

    modelBuilder.Entity<ApplicationUser>().ToTable("User");
    modelBuilder.Entity<IdentityRole>().ToTable("Role");
    modelBuilder.Entity<IdentityUserRole>().ToTable("UserRole");
    modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaim");
    modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogin");
}

Make email as non unique

http://stackoverflow.com/questions/27501533/use-username-instead-of-email-for-identity-in-asp-net-mvc5

Configure below in IdentityConfig.cs

manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
     AllowOnlyAlphanumericUserNames = false,
     RequireUniqueEmail = false                
};

Change password rules

Configure in IdentityConfig.cs

PasswordValidator = new PasswordValidator
{
    RequireDigit = false,
    RequireLowercase = false,
    RequireNonLetterOrDigit = false,
    RequireUppercase = false,
    RequiredLength = 2
};

免责声明:文章转载自《Asp.net Identity 2.0 作弊条》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇(7) MySQL数据库备份详解开发扩展SSH的使用领域和功能 启动一个远程shell 从公网一台电脑登录内网任何一台电脑下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

ipadmini从9.3.5降级8.4.1并完美越狱

ipadmini之前是iOS9.3.5实在是卡的用不了,于是打算降级,但是尝试了包括改版本描述等很多方法一直失败。今天突然成功降级8.4.1并且完美越狱,运行流畅了非常多。方法如下:打开网址:https://www.i4.cn/news_detail_18447.html,下载对应设备的8.4.1自制固件,一般的固件是不可以的。...

Java生鲜电商平台-优惠券系统设计详解

Java Fresh Food电子商务平台-优惠券系统的设计详细说明了优惠券的名称、面额、类型、有效期、使用范围、相互排斥以及作为电子商务最常用的营销手段的平台。用户在收到优惠券之前不知道优惠券的面值和使用限额,但只有在收到之后才知道优惠券的面额和使用限额。用户可在收到优惠券后3天内使用;商户A发放的优惠券只能在购买商户A的商品时使用,一台设备只能使用一张新...

注册支付宝沙箱并测试支付宝扫码连接

2.创建新的支付宝应用程序2.1下载支付宝生成软件密钥#访问“支付宝开发平台”登录并访问开发者中心https://open.alipay.com/platform/home.htm#您可以参考“计算机网站支付”来熟悉计算机支付的整个流程https://docs.open.alipay.com/270/105899/2.1步骤1:创建应用程序(此处使用沙盒环境...

【转】MUD教程--巫师入门教程4

在MUD中,为了解决定时触发某种现象,一般有两种方法,一种是通过call_out()延时呼叫,另一种就是通过心跳。于是,对于要跨起离线前后的象做牢这类的事,大多都是采用condition。附:由于大多数MUD里的心跳是每两秒调一次,5+random是5至14次,因此可以看出每一个condition被调用的时间是平均19秒。然后它会按照condition的名字...

ABB机器人功能程序(FUNC)

功能程序的应用范围非常广泛。熟练的人员可以根据不同的需求创建相应的功能程序。函数程序的固定格式是FUNC,返回结束。在ABB的学习中,许多学生对功能程序几乎一无所知,即使他们真的在使用它。在学习ABB的过程中,我遇到了几个用例,所以我总结了它们以加深我的理解。...

C# winform开发嵌套Chrome内核浏览器(WebKit.net)开发(一)

//Www.cnblogs.com/Maxq/p/6566558.htmlWebKit.net是WebKit的一个net包。使用它,。net程序可以非常方便地集成和使用webkit作为加载网页的容器。EventArgse){WebKit.WebKitBrowser=newWebKitBrowser();this.Controls.Add(浏览器);...