.net MVC Simple Membership Authentication with Database

后端 未结 1 2025
醉话见心
醉话见心 2021-01-30 15:04

Using Code First Entity Framework with .NET MVC 4 I have created a new Web Application and populated the database with object as shown below.

 public class Gratif         


        
相关标签:
1条回答
  • 2021-01-30 15:42

    Remove the AttachDbFileName from the DefaultConnectionString in web.config

    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-GratifyGaming-20120917185558;Integrated Security=True" providerName="System.Data.SqlClient" />
    

    Call the WebSecurity.InitialiseDatabase method in Global.asax.cs

     public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
    
            AreaRegistration.RegisterAllAreas();
            Database.SetInitializer<GratifyGamingContext>(new DatabaseInitializer()); 
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
    
            WebSecurity.InitializeDatabaseConnection(
                      connectionStringName: "DefaultConnection",
                      userTableName: "UserProfile",
                      userIdColumn: "UserID",
                      userNameColumn: "UserName",
                      autoCreateTables: true);
        }
    }
    

    Comment out [InitializeSimpleMembership] in AccountController.cs

     [Authorize]
        //[InitializeSimpleMembership]
        public class AccountController : Controller
    
    0 讨论(0)
提交回复
热议问题