473,671 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global.asax, Caching, LoadXml problems.

I've got a problem with an app I've been working on, the Caching object and
events not firing correctly. In a nutshell: When I'm debugging, and I set a
breakpoint in the removed item call back, the code works correctly. If there
is no debugger it doesn't fire, which causes the app to have problems.

Here's what the code does: The TemplateData class inherits from the DataSet
Object, in the constructor it loads itself with Data from an XML file. I want
this to only happen at Application Start, OR if the file is changed, I want
it to reload the data. I add the TemplateData object to the cache and wire up
a dependency on the xml file that it's loading. If I don't have a break point
either in the Global.asax RefreshDataSetM ethod, OR in the constructor for the
TemplateData class, the data in the Cache does not get populated correctly.
That is to say when I go to get the TemplateData out of the cache, I get a
TemplateData object out, however none of the tables are populated.

As I was writing this I did some more testing and it appears that there are
certain times when the TemplateData is unable to load the file because some
other process has a hold on it. It appears that if you change the xml to a
new value, then change it back to the original values (with notepad) then
this crops up.

This is on Server 2003. Framework 1.1 VS2003.

Any ideas are GREATLY appreciated.

Here's the code for the Global.asax
using System.Collecti ons;
using System.Componen tModel;
using System.Web;
using System.Web.Sess ionState;
using System.Web.Cach ing;
using System.Data;

namespace Foo
{
/// <summary>
/// Summary description for Global.
/// </summary>
public class Global : System.Web.Http Application
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.IContain er components = null;

private static Cache _appCache = null;
private static string _path = null;

// Event Handler for removing the data from the cache.

static void RefreshDataSet (String key, Object item,
CacheItemRemove dReason reason)
{
// Template Data is a class that inherits from the dataset object
TemplateData td = new
TemplateData(_p ath);
LoadCache(td);

}

static void LoadCache(Templ ateData td)
{
// Add the template to the cache, with no time expiration, just a file
dependency.
_appCache.Inser t("td", td, new CacheDependency (_path),
Cache.NoAbsolut eExpiration , Cache.NoSliding Expiration ,
CacheItemPriori ty.Normal, new CacheItemRemove dCallback(Refre shDataSet));

}
public Global()
{
InitializeCompo nent();
}

protected void Application_Sta rt(Object sender, EventArgs e)
{
// Figure out where we are in the world
_appCache =
System.Web.Http Context.Current .Cache;
_path = Server.MapPath( "ExpressTemplat es.xml");

// Load the TemplateData
TemplateData td = new TemplateData();

LoadCache(td);

}

protected void Session_Start(O bject sender, EventArgs e)
{

}

protected void Application_Beg inRequest(Objec t sender, EventArgs e)
{

}

protected void Application_End Request(Object sender, EventArgs e)
{

}

protected void Application_Aut henticateReques t(Object sender, EventArgs e)
{

}

protected void Application_Err or(Object sender, EventArgs e)
{

}

protected void Session_End(Obj ect sender, EventArgs e)
{

}

protected void Application_End (Object sender, EventArgs e)
{

}

#region Web Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
}
#endregion
}
}

Here's the code for the TemplateData class

using System;
using System.Data;
using System.Xml;
using System.Collecti ons;
using System.Web;

namespace FOO
{
/// <summary>
/// Summary description for TemplateData.
/// </summary>
public class TemplateData :DataSet
{
public TemplateData()
{
this.ReadXml(Ht tpContext.Curre nt.Server.MapPa th("ExpressTemp lates.xml"));
}

public TemplateData(st ring path)
{
this.ReadXml(pa th);
}

}
}
Here's the code in a page load where it tries to retrieve the data from the
cache.

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Text;
using System.Web.Cach ing;

namespace FOO
{
/// <summary>
/// Summary description for ListExpressTemp lates.
/// </summary>
public class ListExpressTemp lates : System.Web.UI.P age
{
protected System.Web.UI.H tmlControls.Htm lForm Form1;
protected System.Web.UI.W ebControls.Plac eHolder PlaceHolder1;
protected TemplateTable tt;
protected System.Web.UI.W ebControls.Drop DownList DropDownList1;
protected StyleList sl;

private void Page_Load(objec t sender, System.EventArg s e)
{
//The system will use the offset and numberToDisplay Querystring values
to determine what to display.

// Get the Template data from the Cache
TemplateData td =
(TemplateData)C ache["td"];
sl = new StyleList(td);

int offset = Convert.ToInt32 (Request.QueryS tring["offset"]);
// numberToDisplay is determined by rows * cols
//int numberToDisplay =
Convert.ToInt32 (Request.QueryS tring["numberToDispla y"]);
int rows = Convert.ToInt32 (Request.QueryS tring["rows"]);
int cols = Convert.ToInt32 (Request.QueryS tring["cols"]);

if (rows ==0)
{
rows = 3;
}
if (cols == 0)
{
cols = 3;
}
int filterValue = Convert.ToInt32 (Request.QueryS tring["filter"]);
if (!Page.IsClient ScriptBlockRegi stered("Resubmi t"))
{
Page.RegisterCl ientScriptBlock ("Resubmit", reSubmitCode(ro ws, cols,
filterValue));
}

Filter filterToApply = (Filter)filterV alue;
TemplateList templateList = new TemplateList(fi lterToApply);
tt = new TemplateTable(r ows, cols, offset, templateList, true,
filterValue);
tt.CellPadding = 0;
tt.CellSpacing = 20;
tt.filterDropDo wn.SelectedInde x = filterValue;
tt.GridLines = GridLines.None;
PlaceHolder1.Co ntrols.Add(tt);

DropDownList1.D ataSource = sl.DataLoad();
DropDownList1.D ataValueField = "Name";
DropDownList1.D ataTextField = "FriendlyNa me";

DataBind();
}

private string reSubmitCode(in t rows, int cols, int filterValue)
{
StringBuilder sbScript = new StringBuilder() ;
sbScript.Append ("<script language=\"java script\">");
sbScript.Append ("function reSubmit(caller ){");
sbScript.Append ("var value = caller.value;") ;
sbScript.Append ("window.open(\ "ListExpressTem plates.aspx?row s=" + rows +
"&cols=" + cols + "&filter=\" + value" + ",\"_self\" )");
sbScript.Append ("} ");
sbScript.Append ("</script>");
return sbScript.ToStri ng();
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}
Nov 19 '05 #1
0 1750

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2411
by: Showjumper | last post by:
If i use the cache class in the global asax file in the session sub, can i override for an individual page that has content that will be changing more frequently than the rest of the site? Would i use a dependency in this case? Is there any downside to inseting the cache code in the session start sub?
3
7174
by: Faisal | last post by:
Hi. I'm in the process of moving an application from ASP to ASP.NET, & I'm writing in VB, using VS.NET. I'm new to the .NET framework & have a basic question regarding static objects defined in global.asax. In the global.asax file I want to declare some static objects (like an ADODB.Connection, an ADODB.Recordset, a Scripting.FileSystemObject...), and so I've done so using object tags. For example I have:
2
4778
by: Colin | last post by:
Hi altogether, I ran into a problem with asp.net: I tried to create a pure web application WITHOUT any asax or aspx pages. Only one .dll in the bin folder supplying a HttpApplication and some IHttpModules etc.. All pages are created dynamicly using a xml data source and converting through xslt. Now I have the problem, that asp.net does not start my HttpApplication
6
2630
by: martin | last post by:
Hi, I have noticed that every aspx page that I created (and ascx file) has an assosiated resource file aspx.resx. However what I would like to do is have a single global resource file for the site. The resources in this global resource file will possibly change quite often, there I guess this rules out using web.config as every time web.config alters the application is recompiled, also I am not sure of the possible consequences of...
15
2464
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like to acomplish the same functionality in asp.net.
2
3108
by: R.A.M. | last post by:
I am learning ASP.NET. In Global.asax file I have such code: .... <%@ Import Namespace="System.Web.Caching" %> .... void Application_Error(object sender, EventArgs e) { Exception ex = (Exception) Server.GetLastError(); if (ex != null)
8
13189
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
3
2881
by: thomson | last post by:
Hi All, i do have an website with the URL http://localhost/application/ASEAN-ANZ, Once i hit the application, it goes to the Global.asax. but after that if i tried to change the URL http://localhost/application/en-US, the global.asax is not fired.
10
3573
by: ma | last post by:
Hello, I want to create a global class. To do this I did the followings: 1- Create a class name test. It has a public variable named mystring. public class test { public string mystring = "hello world";
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.