Showing posts with label global. Show all posts
Showing posts with label global. Show all posts

Wednesday, March 28, 2012

The Cache object...

I need to get some clarification on how this object is being implemented:

1. Global to the entire application (single server) -- is this on a per user session? Meaning Cache for user session A will be different from Cache for user session B?
2. What could cause the Cache values to be unreliable aka -- not available or cleared out (prior to expiration time)?

Thanks, Rob.

Hi,

Cache is global to entire application. It is one and the same for all users e.g shared for all users. Session is the user-specific data storage on the server.

Cache values can be cleared under memory pressure (priority depends on if one is explicitly given when cache item is added), and when AppDomain restarts: application pool restarts, web.config change, multiple file operations, maximum number of recompiles etc etc

Therefore you should check cache item for null reference before trying to access it. Steve Smith ahs written excellent article about ASP.NET caching (it's old but still valid):http://msdn2.microsoft.com/en-us/library/aa478965.aspx


Thank you for the response.

So if I were to add something like TextBox.ClientID (as the key) to the Cache, it would be possible for another user session to overwrite or get that same Cache item if they used the same TextBox.ClientID?

Rob.


Yes because it it is essentially one and the same storage for all users.

Thursday, March 22, 2012

The Global.asax.cs

does anyone know how I would write the event :

Application_BeginRequest

from the Global.asax.cs and put this into my webform as inline code?

I think the event you are looking for is ?

Sub Application_Start(ByVal senderAsObject,ByVal eAs EventArgs)

' Code that runs on application startup

EndSub


Thanks but I need it to fire on every postback, not just on application start-up, so something along the lines of (in c#):

private void Application_BeginRequest(Object Sender, EventArgs e)

{

Response.Write("test");

}

I think its the same name as the event in vb too.


you could create a .cs class that would reside in your App_Code folder and then create your function in it. Then in what ever page you need it you would:

if page.ispostback then

Dim gbFunctionsAsNew globalServerFuncitons // The name of the class

Then gbFunctions.YourFunctionNameInTheClass

end if


I guess I should have explained the problem a little more clearly.. The reason I need this event before the page is requested is because of problem with IIS 5.1 (http://support.microsoft.com/?id=910436)

I am uploading several files using file upload controls but each time a postback occurs (i.e. i submit the form) - i am sent to a dns error page because my file sizes total more than my specified limit in the web config.

I therefore am trying to catch the error before the application requests the file headers and throws you to the very unelegant dns error page as described by the microsoft article above.

SO the example workaround they have given in that article i am trying to incorporate using inline code (not code behind). The reason being is because we use several applications that I am writing the upload component for and my task was to create a single .aspx webform that kept all scripts (c#, javaScript, html) all in the one place so we can easily configure it when re-using in the many other apps we have.

Because of this issue the code will never reach the page load event, only the app start, begin request, and on error of the application (in global). So I need to program one of these into my webform.

Does all the above make sense?


So this error occurs on the client and not the server?