0

I am using asp.net identity with EF data first approach. I have hosted my website on appharbor. All of my controllers actions and webapi is working fine except AccountController. When a user tries to signup it gives the Internal server error. The details of error is: enter image description here

My AccountController is:

[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);
        }
    }

I have tried to enable remote connections from this answer. But in SQL Server Configuration Manager the SQL Server Network Configuration does not has the option Protocols for SQLEXPRESS. How can I tackle this issue?

Community
  • 1
  • 1
Irfan Y
  • 1,242
  • 2
  • 21
  • 68
  • the error is telling you pretty much what the error is.. can you duplicate the same issue running it locally .and if not then I would look into first checking the connection string and the database name in regards to how you are connecting – MethodMan Feb 19 '16 at 16:43
  • on localhost everything is working fine. And if there could be a error of connection string then it should give error on every call to database. My database queries are working fine. This error is produced on ONLY `AccountController`. – Irfan Y Feb 19 '16 at 16:49
  • Maybe this can be because `AccountController` (Identity) uses code first approach while i am using data first approach? – Irfan Y Feb 19 '16 at 16:52

0 Answers0