0

I'm trying trying to call Membership.GetUser from from Session_Start in global.asax using ASP.NET identity 2.0

When .Create() is called I get the following erorr at Membership.GetUser:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Web.dll but was not handled in user code

Additional information: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

I suspect this has something to do with OWIN not being initialized yet? Does anyone know if it's possible to get the current GUID from application_start?

Here's my code...

Global.asax

    protected void Session_Start(Object sender, EventArgs e)
    {

        SessionData.Create();
    }

SessionData:

 public class SessionData
    {

        public static void Create()
        {
            using (var db = new BeatBoxV2Context())
            {

                var membershipUser = Membership.GetUser();
                var providerUserKey = membershipUser?.ProviderUserKey;

                if (providerUserKey == null) return;
                var guid = (Guid)providerUserKey;

                var account = db.Account.Find(guid);

                var sessionData = new SessionData
                {
                    UserPermissions= db.Permissions.Where(h => h.Guid == guid).ToList()
                };
            }
        }



        public List<Permissions> UserPermissions
        {
            get { return HttpContext.Current.Session["UserPermissions"] != null ? (List<HolterPermission>)HttpContext.Current.Session["UserPermissions"] : null; }
            set { HttpContext.Current.Session["UserPermissions"] = value; }
        }


    }
Johnny Grimes
  • 411
  • 7
  • 17

1 Answers1

1

OK So the solution was as follows:

  1. Attach the database in App_Data in SQL Express
  2. Run aspnet_regsql from the VS Command Prompt
Johnny Grimes
  • 411
  • 7
  • 17
  • Some more detail would have been good, but +1 for posting a solution to your own problem. That's helpful for people googling. – Rap Feb 22 '17 at 17:17