- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这够好吗?或者我还必须处理 UserStore
吗?如果我确实需要任何建议,我们将不胜感激。我是 ASP.NET Identity 的新手。
using (var applicationDbContext = new ApplicationDbContext())
{
using (var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(applicationDbContext)))
{
}
}
我想这样会更好:
using (var applicationDbContext = new ApplicationDbContext())
{
using (var userStore = new UserStore<ApplicationUser>(applicationDbContext))
{
using (var userManager = new UserManager<ApplicationUser>(userStore))
{
}
}
}
编辑:很高兴我问了这个问题,尽管我可能已经回答了我最初的问题。感谢 Glenn Ferrie,将检查 ASP.NET 依赖项注入(inject)。
最佳答案
这是使用 VS 2015 RC 创建的新 ASP.NET MVC (.NET 4.6) 的一些代码片段。首先是 Startup
类:
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// rest of implementation ommitted for brevity.
然后这是在 Controller 类中访问它的方式:
public class AccountController : Controller
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public AccountController()
{
}
// NOTE: ASP.NET will use this contructor and inject the instances
// of SignInManager and UserManager from the OWIN container
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
{
UserManager = userManager;
SignInManager = signInManager;
}
// there are implementations for the public properties
// 'UserManager' and 'SignInManager' in the boiler plate code
// not shown here
编码愉快!
关于c# - 在 AccountController 之外配置 UserManager 和 UserStore?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196830/
我是 MVC 和 C# 的新手,一直卡在这个错误上。我不知道如何纠正它。任何帮助,将不胜感激。 我正在尝试将客户存储库放入 AccountController 中,以便在创建用户时可以将其与注册用户
我在 Asp .Net Core 2.1 中创建了 - mvc 个人用户帐户并添加了脚手架身份。 我需要将路由 Identity/Account/Register 覆盖到 Account/Regist
我正在 中创建一个 MVC 项目VS2017 并在 VS2015 ,当你创建一个 MVC 模板化的 ASP.NET Web 应用程序时,它会自动为你构建一个帐户 Controller ,它添加了注册和
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve t
那是我的AccountController : [Authorize] public class AccountController : Controller { private UserMa
帐户 Controller 未正确注册 我有一个 ASP.NET MVC 应用程序,其中包含使用身份的个人用户帐户。在我的帐户 Controller 中,我有一个要注入(inject)的 UserMa
因此,我们终于成功地将 Spring 框架从版本 3.2 更新到 4.2.25。经过一些痛苦的过程后,我现在陷入了这个异常: Error create bean with name 'accountC
我在 asp.net 论坛上问过这个问题,但似乎没有人知道我在说什么。我不知道为什么会这样,但我想我会在这里问一下,看看是否有人有一些见识。 早在 MVC2 发布时,它包含一个示例 AccountCo
我正在使用 MVC 5 EF、Identity、Unity 清理旧应用程序我无法弄清楚如何为 AccountController 注册 DI。在里面在下面的例子中我改变了来自以下的空构造函数
我正在尝试在 aspnetuser 中设置列的值来自不同 Controller 的表(不是 accountcontroller )。我一直在尝试访问UserManager但我不知道我们该怎么做。
创建具有单独身份验证的新 .NET Core 2.1 Web 项目时,该项目将与 AccountController 和 ManageController 一起创建。 命令是: dotnet new
此问题与您在 Visual Studio Community 2015 RC 中打开 ASP.NET MVC 应用程序时获得的 Visual Studio 生成的代码有关。 在此生成的代码中,Acco
我一直在观看使用 Spring 进行 Web 开发的教程视频。 Here是完整的源代码。 以下是我向 发送 GET 请求时遇到的错误 localhost:8080/basic-web-app/rest
这够好吗?或者我还必须处理 UserStore 吗?如果我确实需要任何建议,我们将不胜感激。我是 ASP.NET Identity 的新手。 using (var applicationDbConte
我正在开发一个移动应用程序(在 Android 中),它必须连接到 Azure 数据库(该数据库也被该应用程序的 Web 版本使用)。我使用 HttpURLConnection 成功地将 POST/P
我有以下通用 webApi2 AccountController:- private const string LocalLoginProvider = "Local"; privat
我有一个带有登录操作的 AccountController。 我们像这样在我们的应用程序服务中登录用户: _signInManager.AuthenticationManager.SignIn(new
我正在使用 ASP.NET MVC 2 创建一个网站,我正在考虑使用默认的 AccountController 和 View 来照顾用户。 唯一的问题是,我使用的是 Postgres 数据库。 有没有
我创建了一个新的 ASP.NET MVC 5 项目,其中包含个人用户身份验证。然后我继续将 Unity IoC 安装为一个包,并通过在 UnityConfig.cs 中执行以下操作对其进行配置: pu
ASP.NET MVC 1.0(最终版)项目模板具有内置的基本成员资格,但我需要通过两种方式对其进行扩展: 电子邮件确认验证新帐户。 附加字段 在注册 View 上,例如“家庭街道地址”和“部门编号”
我是一名优秀的程序员,十分优秀!