以下是我应用程序所需的代码。我在我的Account Controller文件中遇到了上述错误。我正在使用MVC 4中内置的帐户注册和登录代码。无法注册用户。我在stackoverflow上看到了下面的链接来解决我的错误,但无法解决它。
我遵循的链接
我Web.Config代码中的连接字符串
<connectionStrings>
<add name="PromoteMyNameEntities1" connectionString="metadata=res://*/PromoteDB.csdl|res://*/PromoteDB.ssdl|res://*/PromoteDB.msl;provider=System.Data.SqlClient;provider connection string="data source=Dell-PC\SQLEXPRESS;initial catalog=PromoteMyName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="DefaultConnection" connectionString="data source=Dell-PC\SQLEXPRESS;initial catalog=PromoteMyName;integrated security=True;" providerName="System.Data.SqlClient" />
<connectionStrings>
IdentityModel.cs 文件
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace PromoteMyName.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
我的DbContent文件
public partial class PromoteMyNameEntities1 : DbContext
{
public PromoteMyNameEntities1()
: base("name=PromoteMyNameEntities1")
{
}
AccountController.CS(在这个文件中出现错误)
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
//Getting Error at Line Below
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// 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", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("BusinessCategory", "ClientBusinesses");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}