如何不缓存一个ASP.NET用户控件? [英] How not cache an ASP.NET user control?

查看:103
本文介绍了如何不缓存一个ASP.NET用户控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的OutputCache在我的网页,有一个用户的控制,但我不想缓存此特定用户的控制,因为它涉及到用户登录(如果我访问该网页,我看到的页面,如果我与另一个用户进行认证)。

I'm using OutputCache in my page that has a user control, but I don't want to cache this specific user control because it's related to a user login (if I access the page, I see the page as if I were authenticated with another user).

我怎么能这样做?

推荐答案

我个人使用的属性VaryByCustom是给予登录和注销用户不同的缓存页面访问量:

Personally I use the VaryByCustom attribute to give logged in and logged out users different cached page views:

<%@ OutputCache VaryByCustom="IsLoggedIn" Duration="30" VaryByParam="*" %>

然后在Global.asax中你把

then in global.asax you put

public override string GetVaryByCustomString(HttpContext context,
	string arg)
{
	if (arg == "IsLoggedIn")
	{

		if (context.Request.IsAuthenticated)
		{
			return "Logged in: " + context.User.Identity.Name;
		}
		else
		{
			return "Not Logged In";
		}

	}
	else
	{
		return base.GetVaryByCustomString(context, arg);
	}

}

我只想扔了这一点那里。如何替代控制?

I am just going to throw this out there. How about the substitution control?

<一个href=\"http://msdn.microsoft.com/en-us/library/ms228212.aspx\">http://msdn.microsoft.com/en-us/library/ms228212.aspx

根据MSDN网站:

替代控制,您可以
  的网页,可以在创建区
  动态再更新
  集成到一个缓存的页面。 ...
  替代控制提供
  简化的解决方案,以部分页面
  缓存的网页,其中多数
  内容被缓存。您可以
  输出缓存整个页,然后
  使用替代控制指定
  该页面是免税的部分
  从缓存中。

The Substitution control lets you create areas on the page that can be updated dynamically and then integrated into a cached page. ... The Substitution control offers a simplified solution to partial page caching for pages where the majority of the content is cached. You can output-cache the entire page, and then use Substitution controls to specify the parts of the page that are exempt from caching.

我从来没有使用substituion控制个人,但我刚好看看它有一天,它听起来就像它可以以某种方式注入更新内容到其它缓存的页面输出。

I have never used the substituion control personally, but I just happened to look it up the other day, and it sounded like it can somehow inject updated content into an otherwise cached page output.

这篇关于如何不缓存一个ASP.NET用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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