ASP.NET UserManager.CreateAsync不会在Live Host上添加用户

时间:2015-06-05 13:26:05

标签: asp.net-mvc-4 asp.net-identity usermanager

注册用户的代码在本地针对生产数据库工作,但由于某种原因,在远程主机上,没有添加用户并且返回了Register视图(交付的Register视图,而不是我的那个)我正在使用)。似乎没有发出任何错误,因为我试图从UserManager.CreateAsync任务返回Content任何结果错误。我将在下面发布我的代码,但我不知道它是否会有所帮助。什么可以阻止它在远程主机上工作而不是在本地执行时正常工作?

public async Task<ActionResult> Register(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };

            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                var identity = new IdentityManager();

                if (!identity.RoleExists("profile"))
                {
                    identity.CreateRole("profile");
                }
                bool userAdded = identity.AddUserToRole(user.Id, "profile");

                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                await UserManager.SendEmailAsync(user.Id,
                        "Confirm your account for Site",
                        "Please confirm your account by clicking this link: <a href=\""
                        + callbackUrl + "\">link</a>");
                return View("ConfirmationEmailSent");
            }
            AddErrors(result);
        }

        // If we got this far, something failed, redisplay form
        return View("Login", model);
    }

1 个答案:

答案 0 :(得分:0)

好的,这是由于主持人添加了尾随斜杠规则。它必须与我配置路由的方式发生冲突。