c# - issue Initializing SimpleMembership in filter class -


i trying initialize attribute class reason struggling results.

i have created mvc4 "basic" project template in visual studio 2012. have created folder name filters in project , create class initializesimplemembership.cs. have home controller , associated view , calling [initializesimplemembership] in home controller class no result. application not generating required tables. (note: have created database before)

i trying initialize simplemembership least code can understand , make complex along grows.

in filter folder

using system; using system.data.entity; using system.data.entity.infrastructure; using system.threading; using system.web.mvc; using webmatrix.webdata; using simplelogin_system_04.models;  namespace simplelogin_system_04.filters  {   public class initializesimplemembership : actionfilterattribute   {     private class simplemembershipinitializer     {         public simplemembershipinitializer()         {            try             {                                 websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", autocreatetables: true);             }             catch (exception ex)             {                throw new invalidoperationexception("the asp.net simple membership database not initialized. more information, ex);             }         }     }   } } 

homecontroller

namespace simplelogin_system_04.controllers  { [initializesimplemembership] public class homecontroller : controller {         public actionresult index()     {         return view();     } } } 

web.config ; connection string

<connectionstrings>   <add name="defaultconnection" providername="system.data.sqlclient" connectionstring="data source=(localdb)\v11.0;initial catalog=dd3;integrated security=sspi;attachdbfilename=|datadirectory|\dd3.mdf" /> </connectionstrings> 

i not see invokes constructor simplemembershipinitializer, has code initializing database. why not put code in default constructor initializesimplemembership.

i recommend putting initialization in global.asax application_start method instead of using filter class since putting in homecontroller. reason mvc 4 internet template uses filter on accountcontroller lazy loading security when security being used. if want initialized use global.asax. there description on initialization of simplemembership in article.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -