所以我成功地获得了创建和初始化Identity数据库的解决方案.现在的问题是,当我正在努力时,我不断收到此错误
Cannot create file 'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf'
because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in
the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot create file
'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf'
because it already exists. Change the file …Run Code Online (Sandbox Code Playgroud) 我成功地在我的用户名中获取了非字母数字字符,我现在遇到的问题是当我尝试将角色分配给用户时它会抛出无效的用户名错误.它说"只能包含字母和数字.
这是我添加的用于允许用户名中的字符;
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
var userValidator = UserManager.UserValidator as UserValidator<ApplicationUser>;
userValidator.AllowOnlyAlphanumericUserNames = false;
}
Run Code Online (Sandbox Code Playgroud)
这是我收到错误的地方;
public bool AddUserToRole(string userId, string roleName)
{
var um = new UserManager<ApplicationUser>(
new UserStore<ApplicationUser>(new ApplicationDbContext()));
var idResult = um.AddToRole(userId, roleName);
return idResult.Succeeded;
Run Code Online (Sandbox Code Playgroud)
idResult.Erorrs [0] =" 用户名J.Blow无效,只能包含字母或数字. "
为什么我得到这个.我是否需要在其他地方更改用户名的变体?
提前致谢.
克林特