ASP.NET MVC and role caching?

2019-06-13 16:19发布

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.

1条回答
Viruses.
2楼-- · 2019-06-13 16:37

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.

查看更多
登录 后发表回答