2

I migrated my MVC application to ASP.Net Identity 2.0 from SimpleMembership and remove all reference of latter from application.

But whenever I use the authorize attribute in my controller, I come across the SQLExpress database file auto-creation error: . (BTW, I'm using Ms SQL 2012, and all other functionality is working well with EF)

    [Authorize(Roles = "Admin")]
    public ActionResult UserList()
    {
        var users = db.AspNetUsers.ToList();
        return View(users);
    }

I have tried all the following and still clueless on where am getting it wrong :

  1. Ensure no reference of SimpleMembership anyway in my app and web.config. I even removed the WebMatrix references.
  2. Added filters.Add(new AuthorizeAttribute()) in my startup.
  3. Added following in start up

         app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
    
        // Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login")
        });
    
        // Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    
  4. Configuration.ProxyCreationEnabled not found in my context. So meaning lazy loading is enabled by default.

  5. Added following in my login code :

        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
    ClaimsIdentity identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ExternalCookie);
    AuthenticationManager.SignIn(new AuthenticationProperties()
    {
        IsPersistent = isPersistent
    }, identity);
    
  6. Yes - the role exists in correct case.
Randeep Singh
  • 998
  • 2
  • 11
  • 31
  • Do you consistently get this error or are there times when things work as expected? – Jeremy Cook May 30 '14 at 17:10
  • Might there be anything in web.config that is tying in SimpleMembership? See http://stackoverflow.com/questions/1402430/getting-sqlexpress-database-file-auto-creation-error-for-asp-net-site-that-use – Jeremy Cook May 30 '14 at 17:17
  • Consistently getting it. Web.config is free of any kind of membership reference. – Randeep Singh Jun 01 '14 at 11:44

0 Answers0