在将ASP.NET MVC 5应用程序切换到Azure Redis(Microsoft.Web.RedisOutputCacheProviderNuget包)后,我惊讶地发现OutputCacheAttribute当设置为使用OutputCacheLocation.Any或者OutputCacheLocation.ServerAndClient
[Route("Views/Orders")]
[OutputCache(Duration = 600, Location = OutputCacheLocation.Any)]
public ActionResult Orders()
{
}
Run Code Online (Sandbox Code Playgroud)
随机生成以下错误:
使用"RedisOutputCache"等自定义输出缓存提供程序时,仅支持以下过期策略和缓存功能:文件依赖性,绝对过期,静态验证回调和静态替换回调.
这很奇怪,因为上面的声明明确定义了绝对过期而没有任何先进的东西varybyparam.经过一些搜索,看起来没有解决这个问题,这是非常令人沮丧的.是否有任何外部缓存提供程序与ASP.NET缓存机制兼容?如果没有,您如何在MVC/WebApi应用程序中的集群方案中实现服务器端HTTP输出缓存?
请耐心等待我提供详细信息...
我有一个MVC站点,使用FormsAuthentication和自定义服务类进行身份验证,授权,角色/成员资格等.
登录有三种方式:(1)电子邮件+别名,(2)OpenID,以及(3)用户名+密码.这三个人都获得了一个auth cookie并开始一个会话.前两个由访问者使用(仅限会话),第三个用于作者/管理员使用数据库帐户.
public class BaseFormsAuthenticationService : IAuthenticationService
{
// Disperse auth cookie and store user session info.
public virtual void SignIn(UserBase user, bool persistentCookie)
{
var vmUser = new UserSessionInfoViewModel { Email = user.Email, Name = user.Name, Url = user.Url, Gravatar = user.Gravatar };
if(user.GetType() == typeof(User)) {
// roles go into view model as string not enum, see Roles enum below.
var rolesInt = ((User)user).Roles;
var rolesEnum = …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc authorization forms-authentication session-state
这是我的要求:
我将为N个角色添加用户; 在数据库中定义.
我需要使用authorize属性保护每个控制器操作.
例如,Web应用程序将检查登录用户是否属于这两个角色中的任何一个,如果他们这样做,我让他们进入.如何告诉Authorize属性从我选择的数据库表中获取用户角色?
[Authorize(Roles = "Admin, Technician")]
public ActionResult Edit(int id)
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用谷歌搜索许多不同的页面,但似乎没有一个符合我需要的东西,而且过于复杂.
如果官方文档有我喜欢的东西,因为我没有看到任何我可以使用的东西.
有什么建议?
例如,这个问题有一个非常干净的答案,但我不知道它是完整的还是缺少一些重要的东西.
ASP.NET MVC3角色和权限管理 - >使用运行时权限分配
编辑
我真正想要的是创建自定义角色提供程序,对吗?我是否需要实现此类并将其用作我的角色提供程序?我对此很新,有什么想法吗?
我Microsoft.Web.RedisOutputCacheProvider按照https://msdn.microsoft.com/en-us/library/azure/dn798898.aspx中的说明安装了nuget软件包,用于在多个服务器实例上运行的Azure Web App ,并且收到以下错误:
When using a custom output cache provider like 'MyRedisOutputCache', only the following expiration policies and cache features are supported: file dependencies, absolute expirations, static validation callbacks and static substitution callbacks.
Run Code Online (Sandbox Code Playgroud)
配置设置如下:
<system.web>
<caching>
<outputCache defaultProvider="MyRedisOutputCache">
<providers>
<add name="MyRedisOutputCache"
type="Microsoft.Web.Redis.RedisOutputCacheProvider"
port="1234"
host="[my host]"
accessKey="[my access key]"
ssl="true" />
</providers>
</outputCache>
</caching>
</system.web>
Run Code Online (Sandbox Code Playgroud)
我已经尝试将其设置connectionString为有效的StackExchange.Redis连接字符串,而不是设置单个端口/主机等...但仍然收到相同的错误.
我们还Microsoft.Web.RedisSessionStateProvider使用相同的设置在同一个Web应用程序中运行,没有任何问题.
任何帮助,将不胜感激.