After you came across the same problem and set many breakpoints, I found a solution for my environment, hope others can benefit from this:
inside the App_Start folder
public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { var attr=new InitializeSimpleMembershipAttribute();
Reference Information. In my application, I have 2 views:
- / Account / Registration: this is part of the standard asp.mvc 4 templates and has the attribute [AllowAnonymous]
- / Task: this is an "Index" -Note of a todo list, TaskController has the attribute [Authorize (Roles = "Administrator")]
I always had a problem in the following call:
- debugging session in browser
- successful login
- open the "/ Task" view requiring authorization
- Switch to visual studio and leave the browser open.
- stop debugging
- change the code inside the controller (just set some spaces)
- start debugging session
- click update button in browser
At this point, the "OnActionExecuting" method inside the InitializeSimpleMembershipAttribute class has not yet been called (determined by setting breakpoints)!
But when I opened the View, which does not require authorization (i.e. / Account / Register), the "OnActionExecuting" method was called. After that, I could call / Ask without errors.
Thus, the solution was to create a “pseudo-course” for “OnActionExecuting” at application startup.
source share