When i put this in my Index.cshtml:
@if (Request.IsAuthenticated && User.IsInRole("Admin"))
{
<li><a href="#">Gerenciar</a></li>
}
It throws this error:
An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information:
It is not possible to connect with the SQL Server database
Everything is working SQL Server related, it creates the database, create users fine.
I already looked at other questions and there is no answer that helps!
UPDATE 1
I initialize my context using the default Identity 2.0 context:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<Gatos.Models.Gato> Gato { get; set; }
public System.Data.Entity.DbSet<Gatos.Models.Formulario> Formulario { get; set; }
public System.Data.Entity.DbSet<Gatos.Models.Imagem> Imagem { get; set; }
}
My connection string:
<add name="DefaultConnection" connectionString="Data Source=Bruno-PC;Initial Catalog=Gatos;User Id = sa; Password = *******" providerName="System.Data.SqlClient" />
Update 2
Now my:
[Authorize(Roles="Admin")]
in my controllers are throwing the same error! This is driving me insane!