阅读这篇POST时,您需要了解Asp.net web应用程序,Windows Server AppFabric Cache. 如您不熟悉可以先阅读Windows Server AppFabric Cache 介绍一。
打开Cache PowerShell 控制台(Start –> Windows Server AppFabric –> Caching Administration Windows PowerShell).
启动,如果没有启动
Start-CacheCluster
创建一个新的Cache
New-Cache MySessionStateCache
好的,接下来看WEB.CONFIG如何配制,增加配制节:
<!--configSections must be the FIRST element --> <configSections> <!-- required to read the <dataCacheClient> element --> <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere"/> </configSections>
然后增加配制节点信息,您需要配制主机信息:
<dataCacheClient> <!-- cache host(s) --> <hosts> <host name="YOURHOSTNAME" cachePort="22233"/> </hosts> </dataCacheClient>
在System.web配制节中增加如下配制,注意chcheName是前面用PowerShell命令创建的cacheName
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider"> <providers> <!-- specify the named cache for session data --> <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider , Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" cacheName="MySessionStateCache" sharedId="SharedApp"/> </providers> </sessionState>
下面在一个asp.net page中,测试一下:
1: protected void Page_Load(object sender, EventArgs e)
2: {
3: // Store information into session
4: if (!IsPostBack)
5: {
6: Session["PageLoadDateTime"] = DateTime.Now.ToString();
7: }
8: }
9:
10: protected void GetOrder_Click(object sender, EventArgs e)
11: {
12: OrderDesc.Text = Session["PageLoadDateTime"].ToString();
13: }
运行点击Button你 拿到一个相同的时间从缓存的中。
希望这篇POST对您开发帮助。
作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2010-03-02 在Asp.net中使用JQuery插件之jTip
2007-03-02 Flash 8 Video Encoder安装事项
2007-03-02 Visual Baisc.NET 2005中的泛型