سؤال

I have recently changed by asp.net MVC app to use MVC 5. It also uses entity framework 6.

I have published to Azure Website numerous times in the past, but never with two code first migration configurations. I think this is my problem but I don't know how to fix it.

I have two DbContext classes. One for my domain models and the other for the Identity models. On my local development machine this has caused me no issues. I also have a seed method in the Identity configuration class to create a initial user to login as, since many of my controllers require the [Authorize] attribute.

I have two migration configuration classes, one for each context. I have created a new Windows Azure Website and linked an SQL database to it.

I have downloaded my publish profile which I have used to publish my site. I see both contexts on the settings tab of the Publish Web dialog box. I have selected the appropriate database from the list available for each of my contexts, chosen to use the connection string at runtime and enabled Execute Code First Migrations for both contexts.

When I finally Publish the site it all seems to go well. I see the files through an FTP connection to the site and the site comes up.

However, when I attempt to log in I get an error stating

The ConnectionString property has not been initialized.

After I click the Login button on my Account/Login view.

When I check the tables uses SSMS I see that no tables have been created in SQL.

I can see that my web.config file has been updated. The original connection string has been changed to point to the azure database. Three other connections strings have been added. One more for the domain context that has been appended with _DatabasePublish, and two for the context used for the Identity context, one with and one without the _DatabasePublish suffix.

Can anyone see what I might be doing wrong. I've used Azure with this solution before and had no problems. Please say if you need any other code snippets.

Many thanks.

EDIT...

I found another post that suggested the following:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("SalonContext", throwIfV1Schema: false) // throwIfV1Schema:false was added as the Identity V2 was causing an error in Azure
    {
    }

}

Give it a try and let me know how you get on.

هل كانت مفيدة؟

المحلول

This worked for me.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("SalonContext", throwIfV1Schema: false) // throwIfV1Schema:false was added as the Identity V2 was causing an error in Azure
    {
    }

}

Something to do with Azure and the updates to the identity SDK.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top