Last post Mar 01, 2013 11:59 PM by pranav rastogi
Jan 06, 2013 05:28 PM|jfeeney|LINK
I am using Visual Studio 2012. I have created a new Web application. I am using Code First -- basically I followed the Wingtip Toys tutorial.
I think I have everything working pretty good. Near the end I discovered that if I clicked on the name of the logged in user (which calls Account- Manage.aspx).
I am getting the following error:
System.InvalidOperationException was unhandled by user code HResult=-2146233079 Message=The model backing the 'OpenAuthDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Source=EntityFramework StackTrace: at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6() at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action
action) at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput
input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate) at Microsoft.AspNet.Membership.OpenAuth.EFOpenAuthMembershipDatabase.HasLocalPassword(String membershipUserName) at Microsoft.AspNet.Membership.OpenAuth.OpenAuthManager.HasLocalPassword(String
membershipUserName) at Microsoft.AspNet.Membership.OpenAuth.OpenAuth.HasLocalPassword(String membershipUserName) at HuronWood.Account.Manage.Page_Load() in Account\Manage.aspx.cs:line 29 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
Since this is just a test program...I completely deleted my database an created a new one.
Reset the connection string. I opened Asp.Net Configuration to ensure I could add at least one user. I then ran my program...and as a firt time it created all the database tables. Even though they are blank...everything runs ok.
Even with the new database, I logged in with my user name. It logs in fine. I can also register a new user. But if I click on the user's name (either an old one or a newly created one) then I get the following error message.
Any ideas on where to start to fix this?
Here is the code that exists in the default Manage.aspx page
The error occurs on the line in Page_Load() ... var
public partial class Manage : System.Web.UI.Page
protected string SuccessMessage
protected bool CanRemoveExternalLogins
protected void Page_Load()
//TODO: Figure out what is wrong with Login database that Manage does not work
// Determine the sections to render
var hasLocalPassword = OpenAuth.HasLocalPassword(User.Identity.Name);
setPassword.Visible = !hasLocalPassword;
changePassword.Visible = hasLocalPassword;
CanRemoveExternalLogins = hasLocalPassword;
// Render success message
var message = Request.QueryString["m"];
if (message != null)
// Strip the query string from action
Form.Action = ResolveUrl("~/Account/Manage.aspx");
message == "ChangePwdSuccess" ? "Your password has been changed."
: message == "SetPwdSuccess" ? "Your password has been set."
: message == "RemoveLoginSuccess" ? "The external login was removed."
successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage);
protected void setPassword_Click(object sender, EventArgs e)
var result = OpenAuth.AddLocalPassword(User.Identity.Name, password.Text);
public IEnumerable<OpenAuthAccountData> GetExternalLogins()
var accounts = OpenAuth.GetAccountsForUser(User.Identity.Name);
CanRemoveExternalLogins = CanRemoveExternalLogins || accounts.Count() > 1;
public void RemoveExternalLogin(string providerName, string providerUserId)
var m = OpenAuth.DeleteAccount(User.Identity.Name, providerName, providerUserId)
Response.Redirect("~/Account/Manage.aspx" + m);
protected static string ConvertToDisplayDateTime(DateTime? utcDateTime)
// You can change this method to convert the UTC date time into the desired display
// offset and format. Here we're converting it to the server timezone and formatting
// as a short date and a long time string, using the current thread culture.
return utcDateTime.HasValue ? utcDateTime.Value.ToLocalTime().ToString("G") : "[never]";
Jan 07, 2013 12:20 AM|jfeeney|LINK
As a short term solution, I just created a page called ManageSimple.aspx in the Account folder.
All I did was drag a ChangePassword control into the page. I did nothing on the code behind.
I am not planning on using OpenAuth in my login section. So I left everything in App_Start - AuthConfig.cs commented out.
In the tutorial, I did have the Google log in uncommented but then commented it back out...so I don't know if that triggered something and now it can't find the OpenAuth files.
I saw on one page, that walked through a manual setup of OpenAuth for someone that does not have Visual 2012 that you have two more membership tables.....I don't have those in my database.
Again if someone has some insight to what could be wrong, i would be interested in hearing.
Jan 10, 2013 08:51 AM|molly_c|LINK
I don't have any solution can solve your problem, maybe other can help you, help you to up your post....
Mar 01, 2013 11:59 PM|pranav rastogi|LINK
The reason this was happening is because when you followed the tutorial you were using EF CodeFirst and when you try to register a user the OpenAuth type in Microsoft.AspNet.Membership.OpenAuth tries to create the tables for Oauth login. Since the database
was created using migrations when OpenAuth class tries to modidy the database, it fails. If you update the version of this package to the latest one this issue should have been fixed http://nuget.org/packages/Microsoft.AspNet.Membership.OpenAuth