How do MVC application authentication with Linux?

Asked

Viewed 119 times

4

I have a project in ASP.Net MVC and I’m putting the authentication manually. Everything is going well, but I used as a reference a ready-made project that uses the Entityframework, but I want to use Latin for my operations. The problem is occurring in the code below:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

The error generated is:

Error 2 The type 'System.Data.Entity.Dbcontext' is defined in an Assembly that is not referenced. You must add a Reference to Assembly 'Entityframework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Well, how could I solve this problem without using the Entityframework? Is there any way to use only the Inno for secure authentication? I did a lot of research, but I couldn’t find anything like.

1 answer

1


The error occurs because you added the Entity Framework to your project in an irregular manner. The correct is to add it per package. Open the Package Manager Console (View > Other Windows > Package Manager Console) and type:

Install-Package Entityframework -Version 6.1.2

Try not to install beta versions. On the date of this reply, there are two beta versions in development.

The command not only installs the package for you correctly but also configures some files with entries that are required for Entity Framework to be recognized, such as the Web.config from the root directory.

This solves the problem that generates the error, but does not exclude the use of the Entity Framework, which I believe is the purpose of the question.

In this case, it is wrong for you to use a class derived from IdentityDbContext because IdentityDbContext is part of the Entity Framework.

Correct is for you to derive another class called SignInManager, that is part of the OWIN, Web standard set by Microsoft:

public class MinhaImplementacaoDeSignInManager : SignInManager<MinhaClasseDeUsuario, string>
{
    // Implemente os métodos aqui
}

MinhaClasseDeUsuario need to implement the interface Microsoft.AspNet.Identity.IUser<TKey>.

If you need more help with the methods, I can further refine the question.

  • Thanks for the reply my friend, but the goal is to put authentication without the Entityframework...

  • Yes, I’m already editing the answer. Just a moment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.