0

注册用户的代码在本地针对生产数据库工作,但由于某种原因,在远程主机上,没有添加用户并且正在返回注册视图(交付的注册视图,而不是我正在使用的那个) . 似乎没有发出任何错误,因为我试图从 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);
    }
4

1 回答 1

0

好的,这是由于主机添加尾部斜杠规则。它一定与我配置路由的方式发生冲突。

于 2015-06-05T13:34:32.787 回答