I had a problem with SimpleMembership, Authorize attributes and roles. When I ran my program, I occasionally got the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

To fix it, I had to go to /Account/LogOff and log in again. Very weird problem. I tried Googling it without any luck, until I stumpled upon this blog post. That saved my day. I decided to write down the method here, in case if his blog went down. For users who stumble upon this problem.

The method is to remove [InitializeSimpleMembership] attribute from AccountController class, and comment the following code out (or delete it) in InitializeSimpleMembershipAttribute.cs

Then copy this line to bottom of function Application_Start() in Global.asax.cs file, so it gets initialized immediately when the application starts