所以我为mvc 4项目实现了简单的owin。现在我能够正确地使用appdbcontext类保存和检索用户信息。我的问题是所有其他数据库操作我有wcf服务层,它处理所有数据库调用以保存和检索数据。因此,Web层中不会打开数据库连接。但对于owin,我被迫将连接字符串放在Web层中,并在Web层本身进行db调用。有没有办法让db contxet类将数据发送到我的wcf服务?我的启动类是这个
public class Startup
{
public static Func<UserManager<AppUser>> UserManagerFactory { get; private set; }
public static Func<RoleManager<IdentityRole>> rolemanagerfactory { get; private set; }
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "ApplicationCookie",
LoginPath = new PathString("/Account/Account/Login")
});
UserManagerFactory = () =>
{
var usermanager = new UserManager<AppUser>(new UserStore<AppUser>(new AppDbContext()));
usermanager.UserValidator = new UserValidator<AppUser>(usermanager)
{
AllowOnlyAlphanumericUserNames = false
};
return usermanager;
};
rolemanagerfactory = () =>
{
var rolemanager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new AppDbContext()));
return rolemanager;
};
}
}
我给用户管理员的AppUser类就是这个
public class AppUser :IdentityUser
{
public string firstname { get; set; }
public string lastname { get; set; }
public string addressline1 { get; set; }
public string addressline2 { get; set; }
public string addressline3 { get; set; }
public string city { get; set; }
public int citycode { get; set; }
public string state { get; set; }
public int statecode { get; set; }
public string pincode { get; set; }
public string country { get; set; }
public int countrycode { get; set; }
public string mobile { get; set; }
public string baseGPSLong { get; set; }
public string baseGPSLat { get; set; }
public bool IsActive { get; set; }
}
当然appdbcontext类是这个
public class AppDbContext : IdentityDbContext<AppUser>
{
public AppDbContext()
: base("CSPL.Epons.Data.Properties.Settings.eponsmasterConnectionString")
{
}
}