c# - Exception thrown when the DB doesn't exist yet and the application tries to create it -
this happens only, when there no db yet , has created. ideas on how fix this?
"object reference not set instance of object." gets thrown here:
public static void initializeidentityforef(applicationdbcontext db) { using (var applicationdbcontext = new applicationdbcontext()) { var usermanager = httpcontext.current.getowincontext().getusermanager<applicationusermanager>(); // exception "object reference not set instance of object." gets thrown here. the application stops somewhere in class:
using microsoft.aspnet.identity; using microsoft.aspnet.identity.entityframework; using system.web.mvc; using webapp.models; using webapp.services; namespace webapp.razor { public abstract class customwebviewpage<tmodel> : webviewpage<tmodel> { /// <summary> /// application db context /// </summary> protected applicationdbcontext applicationdbcontext { get; set; } /// <summary> /// user manager - attached application db context /// </summary> protected usermanager<user> usermanager { get; set; } public customwebviewpage() { this.applicationdbcontext = new applicationdbcontext(); this.usermanager = new usermanager<user>(new userstore<user>(this.applicationdbcontext)); } public user currentuser { { var currentuser = this.usermanager.findbyid(user.identity.getuserid()); if (currentuser == null) { currentuser = new user { name = "", username = "", email = "", id = "" }; } return currentuser; } } } }
Comments
Post a Comment