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