Set ASP.NET Identity ConnectionString property in .NET 4.5.1

前端 未结 2 1269
刺人心
刺人心 2021-02-06 06:59

So basically after finally learning how to change OpenAuth to not use DefaultConnection in .NET 4.5, I\'ve moved on to 4.5.1, rendering those learnings moot. The duties of AuthC

2条回答
  •  心在旅途
    2021-02-06 07:48

    Release Candidate

    Works with Microsoft.AspNet.Identity.EntityFramework 1.0.0-rc1

    In the parameterless constructor for AccountController, change the line

    IdentityManager = new AuthenticationIdentityManager(new IdentityStore());
    

    to

    IdentityManager = new AuthenticationIdentityManager(new IdentityStore(new DefaultIdentityDbContext("YourNameOrConnectionString")));
    

    and you're good to go.

    Release

    Works with Microsoft.AspNet.Identity.EntityFramework 1.0.0

    Similar to what we did for release candidate, but we do this in a different place. Open IdentityModels.cs that was created as part of the VS template and add the following constructor to the ApplicationDbContext class:

    public ApplicationDbContext(string nameOrConnectionString)
        : base(nameOrConnectionString)
    {
    }
    

    and you can now change the parameterless constructor in AccountController from

    public AccountController()
        : this(new UserManager(new UserStore(new ApplicationDbContext())))
    {
    }
    

    to

    public AccountController()
        : this(new UserManager(new UserStore(new ApplicationDbContext("YourNameOrConnectionString"))))
    {
    }
    

    and your done.

提交回复
热议问题