我正在使用asp.net身份和EF数据第一种方法。我在appharbor上托管了我的网站。除AccountController
之外,我的所有控制器操作和webapi都正常工作。当用户尝试注册时,会给出Internal server error
。错误的细节是:
我的AccountController
是:
[Authorize]
public class AccountController : Controller
{
private Entities db = new Entities();
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
}
[HttpPost]
[AllowAnonymous]
public async Task<JsonResult> RegisterUser(string email, string password = "aa")
{
var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
if (!roleManager.RoleExists("Admin"))
{
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "Admin";
roleManager.Create(role);
}
var ab = email.Split('@');
var user = new ApplicationUser() { UserName = email };
user.Email = ab[0];
UserManager.PasswordValidator = new PasswordValidator
{
RequiredLength = -1
};
var result = await UserManager.CreateAsync(user, password);
if (result.Succeeded)
{
var currentUser = UserManager.FindByName(user.UserName);
var roleresult = UserManager.AddToRole(currentUser.Id, "Admin");
try {
await SignInAsync(user, isPersistent: true);
}
catch (Exception e)
{
string s = e.ToString();
}
var id = user.Id;
var data =await db.AspNetUsers.FindAsync(id);
if (password == "aa")
{
data.IsPasswordSaved = false;
}
else
{
data.IsPasswordSaved = true;
}
db.Entry(data).State = System.Data.Entity.EntityState.Modified;
await db.SaveChangesAsync();
return Json("Done", JsonRequestBehavior.AllowGet);
}
return Json("Error", JsonRequestBehavior.AllowGet);
}
}
我尝试从this回答启用远程连接。但在SQL Server Configuration Manager
中,SQL Server Network Configuration
没有选项Protocols for SQLEXPRESS
。我该如何解决这个问题?