นั่งเสียเวลาเป็นชม.ๆ –” มันอะไรกันนักหนาเนี่ย 55+ ไปได้วิธีมาจากเว็บ Narisa และ Greatfriends ได้ความว่า ใน ASP.NET 2.0 ได้เพิ่มสิ่งที่เรียกว่า File Change Notifications (FCN) หรือ Directory Monitoring เพื่อคอยจับ Directory ทุกครั้งที่มีการ Rename หรือ Delete มันจะ Restart Application ดังนั้น Session State ที่เก็บแบบ InProc จะหายไปด้วย (เออเอากับมัน…)
เกริ่นซะยาวมาดูวิธีแก้กันเลยให้ใส่ Code ด้านล่างนี้ ในไฟล์ “Global.asax.cs” ที่ Events Application_Start() และใช้ using System.Reflection ด้วย ซึ่งการทำงานของมันจะปิด Directory Monitoring ทันทีที่ Application เริ่มทำงาน
System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
สำหรับคนที่ยังไม่เคยใช้ Global.asax.cs ขออธิบายนิดนึงครับ
ไฟล์ Global.asax.cs จะมีไฟล์ Global.asax Inherits มาเรียกอีกทีนึง และทั้งสองไฟล์จะต้องอยู่บนสุดของเว็บไซต์เท่านั้นนะจ๊ะ ยิ่งอธิบายยิ่ง”งง” ดาวน์โหลดไปเลยดีกว่าตรงนี้ผมใส่ Code ด้านบนไว้ให้เรียบร้อยแล้วครับ
คลิกที่นี่เพื่อดาวน์โหลด Global.asax และ Global.asax.cs
เมื่อเราใส่ Code เรียบร้อยแล้วหากเกิดกรณี Error ประมาณนี้
Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request failed. Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
ให้ไปที่ไฟล์ web.config แล้วไปเพิ่มตาม Code ด้านล่าง
<system.web>
<trust level="Full" originUrl=""/>
</system.web>
เป็นอันเสร็จเรียบร้อยครับ
ที่มา :
http://www.narisa.com/forums/index.php?showtopic=27585
http://www.greatfriends.biz/webboards/msg.asp?id=106519
RSS Feed
Twitter
June 25th, 2010
admin | 1,733 views
Posted in 
