C# ASP.NET Web表单和标识:将IdentityModels.cs移动到另一个项目
我正在尝试将IdentityModels.cs移到另一个项目中,以使网站与数据访问层分离 我遵循了本教程: 并在这里检查了这个问题: 但我仍然感到困惑,因为IdentityModels引用了另一个名为ApplicationUserManager的类,如下所示:C# ASP.NET Web表单和标识:将IdentityModels.cs移动到另一个项目,c#,asp.net,.net,webforms,asp.net-identity,C#,Asp.net,.net,Webforms,Asp.net Identity,我正在尝试将IdentityModels.cs移到另一个项目中,以使网站与数据访问层分离 我遵循了本教程: 并在这里检查了这个问题: 但我仍然感到困惑,因为IdentityModels引用了另一个名为ApplicationUserManager的类,如下所示: public class ApplicationUser : IdentityUser { public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager ma
public class ApplicationUser : IdentityUser
{
public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
{
//code removed for simplicity
}
}
当我去搜索那个类的位置时,我在位于App_Start/IdentityConfig.cs中的一个类的网站项目中找到了它
//...More code in the upper section
public class SmsService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
}
}
// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
//More code bellow this...
/…上半部分有更多代码
公共类SMS服务:IIdentityMessageService
{
公共任务SendAsync(IdentityMessage消息)
{
//在此处插入您的短信服务以发送短信。
返回Task.FromResult(0);
}
}
//配置此应用程序中使用的应用程序用户管理器。UserManager在ASP.NET标识中定义,并由应用程序使用。
公共类应用程序管理员:UserManager
{
公共应用程序服务器管理器(IUserStore存储)
:基地(商店)
{
}
//下面是更多的代码。。。
现在,这让我来到这里,因为我真的迷失在新的ASP.NETIdentity框架中,我一直在努力解决那些看起来并不那么简单的简单问题
如何将IdentityModel移动到另一个项目中而不破坏我的网站
其他一些数据:
- 使用VS 2013社区
- 使用.NET Framework 4.5.1
- Microsoft.AspNet.Identity.EntityFramework
- Microsoft.AspNet.Identity.Owin
- Microsoft.Owin(我刚从NuGet获得最新版本,它是 稍新,并迫使我更新上的现有引用 web项目–易于使用NuGet的管理包>更新)
- 对“System.Web.Mvc的引用
- 对“System.Web”的引用-注意:有必要添加一个项目 由于我使用的是HttpContextBase,因此引用System.Web, 类库中的HttpContext(这一点起初令人困惑,因为 我的类已经有了一个“using System.Web”语句。我不会详细说明 为什么在这里,但要确保您的项目中有“System.Web” 参考(仅System.Web.Mvc是不行的)
public类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“XyzContext”,throwifvv1schema:false)
{
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
}
此时,编译给了我一个自定义类中的“GetOwinContext”错误,该类是我为集中某些aspnet标识业务逻辑而创建的。要解决此问题,我需要在类库中使用另一个NuGet包:Microsoft.Owin.Host.SystemWeb
之后一切都很好。我也有同样的问题。我正在研究,如果我得到答案,我会发布它。不要以为我没有看到你的答案,我将一步一步地检查你的答案,看看它是否对我有效。谢谢分享,我会让你知道它是如何进行的。永远不会太晚。我一步一步地测试了你的建议,效果很好。您应该更正Microsoft.AspNet.Identity.Owen到Owin包名称中的一个键入错误。这是一个很好的开始,谢谢!:)但是我仍然有一个问题,您是否同时使用datacontext?用于您的业务表和
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("XyzContext", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}