Reputation: 29199
I have the following Asp.Net MVC 4 code and it raise the error on line 18 of controller DealController
. Right now it only happen after I rebuild the project when I'm debugging using VS 2012 on my local PC.
Line 16: private IQueryable<Deal> Deals
Line 17: {
Line 18: get { return User.IsInRole("Admin") ? _db.Deals : _db.Deals.Where(d => d.CreatedBy == User.Identity.Name); }
Line 19: }
You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.
Should I add attribute [InitializeSimpleMembership]
on all the controllers which calls User.IsInRole()
or User.Identity.Name
? Right now it's only added on AccountController
.
Upvotes: 2
Views: 7108
Reputation: 29199
Adding [InitializeSimpleMembership]
for the controller solved the issue.
Upvotes: 7