Matteo Mosca
Matteo Mosca

Reputation: 7448

ASP.NET MVC and role caching?

I am developing an ASP.NET MVC app with custom membership and role providers.

My custom role provider uses LinqToEntities to query the user/role mapping table and retrieve if a user is in a role or not.

When running on debug, local machine, everything is fine. When deploying on IIS7 however, I have this strange behavior:

When I change roles to a user, and then login with that user, it retains the old roles, instead of the new ones. It's like they are cached somewhere, but I already set the cacheRolesInCookie="false" option in the Web.config

Reading on the web, I saw that the option I mentioned is just a directive for the provider, meaning if I don't implement its usage, it will be ignored, is that right?

This leaves me puzzled. My provider should perform a fresh query every time a method is called. It works locally, but not on the deploy machine with IIS7.

Anyone knows if there's any hidden setting in IIS7 to make things work right?

Thanks.

Upvotes: 0

Views: 910

Answers (1)

Matteo Mosca
Matteo Mosca

Reputation: 7448

After a long time I found the solution.

The problem was residing on the EF context I was using to read the users/roles.

I fixed it resintantiating the context every time a role is checked, instead of keeping the same context until application restarted.

Upvotes: 2

Related Questions