ASP.NET MVC和角色缓存? [英] ASP.NET MVC and role caching?

查看:65
本文介绍了ASP.NET MVC和角色缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发具有自定义成员资格和角色提供程序的ASP.NET MVC应用。

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

我的自定义角色提供程序使用LinqToEntities查询用户/角色映射表并检索

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

在调试,本地计算机上运行时,一切都很好。但是,当在IIS7上进行部署时,我有一个奇怪的行为:

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

当我将角色更改为用户,然后用该用户登录时,它将保留旧的角色,而不是新的。就像它们被缓存在某个地方一样,但是我已经在Web.config中设置了 cacheRolesInCookie = false 选项

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?

这让我感到困惑。每次调用方法时,我的提供程序都应执行全新查询。它在本地运行,但不能在使用IIS7的部署计算机上运行。

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.

任何人都知道IIS7中是否存在任何隐藏设置来使事情正常进行?

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

谢谢。

推荐答案

很长一段时间后,我找到了解决方案。

After a long time I found the solution.

问题出在我用来读取用户/角色的EF上下文中。

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.

这篇关于ASP.NET MVC和角色缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆