使用asp.net mvc5,我的用户管理系统似乎工作.我可以使用谷歌或名称/密码登录..
但现在我正在开发一个用户管理界面,我需要能够删除现有用户.这开始向我展示用户管理系统是多么令人困惑.有很多不同的方式来处理用户......其中一些不起作用.
我阅读的大多数地方,都在谈论使用Membership.DeleteUser().
但这不起作用......
用户创建了.
var user = new ApplicationUser()
{
UserName = model.UserName,
Email = model.Email,
ConfirmationToken = confirmationToken,
IsConfirmed = false
};
var result = await UserManager.CreateAsync(user, model.Password);
Run Code Online (Sandbox Code Playgroud)
现在稍后..如何删除这样的用户?(给出其名称或用户ID)
我已经尝试过在各种搜索中出现最多的东西..提出了会员资格作为解决方案.但这肯定不适合MVC5?例如
var allusers = Membership.GetAllUsers(); // allusers is empty
bool success = Membership.DeleteUser(model.name); // <-- success = false
Run Code Online (Sandbox Code Playgroud)
我可以让所有用户使用这种方法..
ApplicationDbContext db = new ApplicationDbContext();
foreach (var user in db.Users) { ... }
Run Code Online (Sandbox Code Playgroud)
我可以找到一个单独的用户..
ApplicationDbContext db = new ApplicationDbContext();
var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
ApplicationUser user = um.FindById(model.userId); …Run Code Online (Sandbox Code Playgroud) 我一直在努力让WCF数据服务服务器工作几天.我终于在今天退缩了,只是尝试完全按照快速启动的方式展示......没有其他......以及完全新鲜的项目.肯定会有用.
但它没有..它失败的方式与我的其他测试相同.
我只是跟着这个例子.使用Visual Studio 2013进行Web Express和托管正在使用IIS Express.我已安装WCF工具5.6版,以便Visual Studio具有WFC数据服务5.6模板.
它的要点是
创建ASP.Net应用程序选择MVC类型,不为MVC以外的任何内容添加任何文件夹,也不添加单元测试,个人帐户认证.
为NorthWind数据库添加ADO.Net实体数据模型,在web.config中称为NorthwindEntities,导入所有表.
添加WCF数据服务5.6项,将其命名为NorthWind.svc.
将NorthWind.svc.cs支持代码更改为以下内容.
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace StackOverflowApp
{
public class NorthWindService : DataService<NorthwindEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead | EntitySetRights.WriteMerge | EntitySetRights.WriteReplace );
config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead| EntitySetRights.AllWrite);
config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在它已准备好构建和运行..它应该工作..是吗?
我运行它,然后导航到服务..我受到以下投诉的欢迎.
<div id="content"> …Run Code Online (Sandbox Code Playgroud)