ÈÃViewState ±£´æÓÚ·þÎñÆ÷¶ËÎļþ (asp.net C#)
½«ViewState³Ö¾Ã»¯±£³ÖÔÚ·þÎñÆ÷¶ËÎļþµÄ´úÂ룬ÕâÑùViewState²»Õ¼ÓÃÍøÂç´ø¿í£¬Òò´ËÆä´æÈ¡Ö»ÊÇ·þÎñÆ÷µÄ´ÅÅ̶Áȡʱ¼ä¡£²¢ÇÒËüºÜС£¬¿ÉÒÔ˵ÊÇ´ÅÅÌËæ±ãתһȦ¾ÍÄÜͬʱ¶ÁÈ¡ºÃ¶àViewState£¬Òò´Ë¿ÉÒÔ˵“²»Õ¼Ê±¼ä”¡£ÎªÁËÔÙ“²»Õ¼´ÅÅÌʱ¼ä”£¬ÎÒ»¹Ê¹ÓÃÁË»º´æ¡£
´´½¨Ò»¸ö»ùÀà:
public class
BasePage : System.Web.UI.Page
{
protected override object
LoadPageStatefromPersistenceMedium()
{
var viewStateID = (string)((Pair)base.LoadPageStatefromPersistenceMedium()).Second;
var stateStr = (string)Cache[viewStateID];
if (stateStr == null)
{
var fn = Path.Combine(this.Request.PhysicalApplicationPath, @"App_Data/ViewState/" + viewStateID);
stateStr = File.ReadAllText(fn);
}
return new ObjectStateFormatter().Deserialize(stateStr);
}
protected override void
SavePageStateToPersistenceMedium(object state)
{
var value = new ObjectStateFormatter().Serialize(state);
var viewStateID = (DateTime.Now.Ticks + (long)this.GetHashCode()).ToString(); //²úÉúÀëÉ¢µÄidºÅÂë
var fn = Path.Combine(this.Request.PhysicalApplicationPath, @"App_Data/ViewState/" + viewStateID);
ThreadPool.QueueUserWorkItem(obj => File.WriteAllText(fn, value));
Cache.Insert(viewStateID, value);
base.SavePageStateToPersistenceMedium(viewStateID);
}
}
}
Global.asax,ÒÔÏ´úÂëÒ²¿ÉÒÔ²»Óãº
protected void
Application_Start(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(this.Server.MapPath("~/App_Data/ViewState/"));
if (!dir.Exists)
dir.Create();
else
{
DateTime nt = DateTime.Now.AddHours(-0.3); //ɾ³ý15·ÖÖÓÒÔÇ°µÄ»º´æÎļþ
FileInfo[] fiArr = dir.GetFiles();
foreach (FileInfo f in fiArr)
{
if (f.CreationTime < nt)
{
f.Delete();
}
}
}
}
ʹÓ÷½·¨:
ÆäËüÒ³Ã
Ïà¹ØÎĵµ£º
¿ª·¢»·¾³:WIN XP VS2005
Êý¾Ý¿â:SQL server 2000
´Ë´¦²»¿¼ÂÇ°²È«ÎÊÌâ.
¾ßÌåÈçÏÂ:
Ê×ÏȽ¨Á¢Ò»¸öÊý¾Ý¿âºÍÒ»¸ö±í½á¹¹²¢ÔÚ±íÖÐÊäÈëһЩÊý¾ÝÒÔ±ã²âÊÔ:´Ë²½ÂÔ¹ý
´ò¿ªVS2005н¨Ò»¸öÍøÕ¾²¢Ìí¼ÓÒ»¸öHTMLÒ³
ÔÚĬÈϵÄDefault.aspxÖзÅÈëGridview¿Ø¼þÓÃÓÚÏÔʾÊý¾Ý
.cs´úÂë
using System;
using System.Data;
usi ......
----------------------ModalPopupExtender
D:\sourceforge\asp.net\AjaxControlToolkit_net20\SampleWebSite\ModalPopup\ModalPopup.aspx
// linkbutton1Ôö¼ÓÀ©Õ¹ModalPopupExtenderÊôÐÔ:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Click here to change the paragraph styl ......
ASP.NET ProfileÊôÐÔ
×÷Óãº
´æ´¢ºÍʹÓÃΨһÓëÓû§¶ÔÓ¦µÄÐÅÏ¢
Õ¹ÏÖ¸öÈË»¯°æ±¾µÄWebÓ¦ÓóÌÐò
Óû§µÄΨһÉí·Ý±êʶÔÚÔٴηÃÎÊʱʶ±ðÓû§
ASP.NET ProfileÈçºÎ¹¤×÷
ÄãµÄWebÓ¦ÓóÌÐòÔËÐÐʱ£¬ASP.NET´´½¨Ò»¸ö´ÓProfileBaseÀද̬¼Ì³ÐÏÂÀ´µÄ¶¯Ì¬Éú³É³öÀ´µÄProfileCommonÀà¡£¶¯Ì¬ProfileCommonÀà°üº¬ÁËÄãÔÚWebÓ¦ÓóÌÐòÅäÖÃÎļ ......
ÔÚʹÓÃÍøÕ¾¹ÜÀí¹¤¾ß×öµÇ¼ҳÃæµÄʱºòÓöµ½µÄÎÊÌâ
ËùÓöÎÊÌ⣺½øÈëVisual Studio 2005µÄ“ÍøÕ¾”²Ëµ¥µÄ“ASP.NET ÅäÖԺ󣬵ã»÷“°²È«”ºó£¬³öÏÖÈçϵijö´íÐÅÏ¢£º
“Ñ¡¶¨µÄÊý¾Ý´æ´¢Çø³öÏÖÎÊÌ⣬ÔÒò¿ÉÄÜÊÇ·þÎñÆ÷Ãû³Æ»òƾ¾ÝÎÞЧ£¬»òÕßȨÏÞ²»×ã¡£Ò²¿ÉÄÜÊÇ ......