Note that there are some explanatory texts on larger screens.

plurals
  1. POinitialize simple membership in MVC 4
    primarykey
    data
    text
    <p>I have a problem with my MVC 4 application which used to work fine, but stopped for some reason, and I cannot find out why. I use simple memebrship provider and code first approach. This is my Index action method in the home controller</p> <pre><code>[Authorize] public class HomeController : Controller { private IActivityRepository repo; public HomeController(IActivityRepository activityRepository) { repo = activityRepository; } //Allow anonymous to allow to create database if there isn't one yet [AllowAnonymous] public ActionResult Index() { repo.InitializeDatabase(); //!!!!!!!!!!!!!!!!!!!!! return RedirectToAction("ManageActivities"); } </code></pre> <p>The whole concept of mine is that if database doesn't exist it gets created in InitializeDatabase Method. Then user is redirected to ManageActivities action method which is decorated with [Authorize] attribute, what in effect takes user to login action method in AccountCotroller (out of the box in MVC4). This controller is decorated with [InitializeSimpleMembership], what fires InitializeSimpleMembershipAttribute filter. </p> <p>This logic worked fine for me a while ago. Today I wanted to create a new database for testing purposes. When I create data context I call the base class with a custom name for the database like so:</p> <pre><code>public class ActivityLogContext : DbContext { public ActivityLogContext() : base("ActivitiesConnection") { } </code></pre> <p>So I've changed details for my connection string and run the application. Unfortunatelly, for some reason the code hits InitializeSimpleMemebership filter before running Index method from the home controller (even though its decorated with [AllowAnonymous]). In effect simple membership is initialized but database does not yet exist, what runs me into error.</p> <p>My question is, why InitializeSimpleMemebership filter is getting released on application start if Index method doesn't require authorization?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload