asp.net mvc 4 - initialize simple membership in MVC 4 -
i have problem mvc 4 application used work fine, stopped reason, , cannot find out why. use simple memebrship provider , code first approach. index action method in home controller
[authorize] public class homecontroller : controller { private iactivityrepository repo; public homecontroller(iactivityrepository activityrepository) { repo = activityrepository; } //allow anonymous allow create database if there isn't 1 yet [allowanonymous] public actionresult index() { repo.initializedatabase(); //!!!!!!!!!!!!!!!!!!!!! return redirecttoaction("manageactivities"); } the whole concept of mine if database doesn't exist gets created in initializedatabase method. user redirected manageactivities action method decorated [authorize] attribute, in effect takes user login action method in accountcotroller (out of box in mvc4). controller decorated [initializesimplemembership], fires initializesimplemembershipattribute filter.
this logic worked fine me while ago. today wanted create new database testing purposes. when create data context call base class custom name database so:
public class activitylogcontext : dbcontext { public activitylogcontext() : base("activitiesconnection") { } so i've changed details connection string , run application. unfortunatelly, reason code hits initializesimplememebership filter before running index method home controller (even though decorated [allowanonymous]). in effect simple membership initialized database not yet exist, runs me error.
my question is, why initializesimplememebership filter getting released on application start if index method doesn't require authorization?
i eliminate use of initializesimplemembership discussed in article. move initialization global.asax application_start method , initialization there also, happens in correct sequence.
Comments
Post a Comment