# Sunday, 29 April 2007

Hi again..

I am here again with the same issue, and this is because a long conversation that I had with Oren Ellenbogen (ex. co-worker) about some extending and refactoring of the former post solution (you can see it here if you missed it).

The main goal in the Session/Application objects encapsulation was the ability of avoiding casting each time that we would use these objects, this is annoying especially we uses the specific object in most of the flows of the application.
The other goal is getting the ability of managing these objects in one centered place.

NOW, some extesibility...
This object need to be maintened everytime that we want to add a new session/application object. Good usage of generics will solve this problem -> this will bring up the ability of adding new objects everywhere that we'll want (example in the continuance...).

So, look at the following implemetation:

public static class SessionRepository
   public static bool IsExist(string objectKey)
      return HttpContext.Current.Session[objectKey] != null;

   public static TObject GetInstance<TObject>(string objectKey)
      return (TObject)HttpContext.Current.Session[objectKey];

   public static void Add<TObject>(string objectKey, TObject obj)
      HttpContext.Current.Session.Add(objectKey, obj);

Some usage:

if (SessionRepository.IsExist("SomeObjectKey"))
   SomeObject obj = SessionRepository.GetInstance<SomeObject>("SomeObjectKey");

   // Do your things...

SessionRepository.Add<SomeObject>("SomeObjectKey", SomeObject);

This way of implementation comes to help us with the casting issue and it gives up extensibilty options. I think that there is a small disadventage here - we also need to remeber the keys of the objects in the session object - but there is nothing perfect.


  1. Both of the solutions are good and each has each advantages/disadventages, you can prefer the best way of using.
  2. The first way (shown in the former post) enables you a direct access to the object stays in the session/application, but need to be managed for each time we want to add new object into the session/application.
  3. The way shown here holds a different approach, enables you extensibility, but you don't have the explicit access to these objects.
  4. In both ways, the casting issue is covered!

That's it for today.

Commets will be appriciated...

Sunday, 29 April 2007 14:41:05 (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Thursday, 19 April 2007


In most of ourweb applications, we (must) use the session object, which gives us better way of data storing (session object lives over the HTTP protocol and exists all over the user's session lives {except of expiration etc...}).

The access to the session objects and variables is quite easy and simple, BUT, what happens when you want to store your complex struct or object in the session (even some other system object)? THEN, you must cast this session variable, and check if it alives before you can access its properties etc...

I have a good suggestion that also will encapsulate the sesison's variables and will be easy to manage, pay attention:

Firstable, I created a static class, called: Repository, which will expose the session variables as properties, and the access to these objects will be much more easy and explicit.

The repository static class:

public static class Repository
    public static SomeObject SessionSomeObject
           return HttpContext.Current.Session["SomeObject"] as SomeObject;
            HttpContext.Current.Session["SomeObject"] = value;

    // Some more properties declarations

(This class gathers all the session/application members = good and convenient code management).

NOW, look at the 'old fashioned' and regular way that the sytax suggests us (if we don't use the Repository static class):

if (Session["SomeObject"] != null)
   myObject = ((SomeObject)Session["SomeObject"]).MyProperty;
   // bla bla bla...

In the above example, we must check if the object is alive in the session firstly if we want to access its properties (unless we do it, it will throw us a runtime error). In the bottom example we cover this case with one sentense of code:

myObject = Repository.SessionSomeObject.MyProperty;

Here, even if the object is null, it will we create an instance of it and will return us some default value of the object's property.

Have a good day...

This code relates also to the Application object!

Thursday, 19 April 2007 12:19:24 (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Tuesday, 17 April 2007

Hey fellows...

I wanted to share you with an event that happened these days, my friend - Oded Balilty won the Pulitzer Prize for his photograph.

This is a great honor also to Oded and as well to Israel state of course.

This photograph displays a lone settler woman defying Israeli security forces, so take a look:

Well done Oded, keep successing alive...

With regards,

Tuesday, 17 April 2007 11:23:20 (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Wednesday, 11 April 2007

You can download it, it is ready, right from the oven...

The best thing that I found there is the Validation Application Blocks, which is new and wasn't in the earlier versions.
"Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications." (quoted form the msdn site).

You can find it here: http://msdn2.microsoft.com/en-us/library/aa480453.aspx


Wednesday, 11 April 2007 10:40:47 (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback


Some intro:
I am starting to migrate a classic asp web application (quite complicated) to .NET 2.0 environment and in the begining (of course) I am starting to learn the functionality of the existing web app.

This morning I came to work and started to rrun the asp web app, but my IIS (5.0) seemed to be dead. I couldn't run anything, even the localhost help page to get some information.

I disabled the "Show friendly HTTP error messages" from the explorer advanced options, and | got this messgae: "The server has encountered an error while loading an application during the processing of your request" - Interesting...

After doing some actions in the IIS, I succeeded solving the problem myself, I just changed the application protection to Low in the virtual directory folder properties.

Some info:
The Application Protection drop-down determines if this IIS Application is to be isolated in its own process, pooled with other apps, or in-process with IIS. This feature comes to give us the ability of isolating applications, configuring them to run in a process (memory space) that is separate from the Web server and other applications. You can configure applications to have one of three levels of application protection: Low, Medium, High.

Another thing is: The application protection determines how memory resources are allocated for ASP pages:

  • Low (IIS Process): this level runs ASP pages using the same resources as the web service. The advantage of the low level is that you are given the most permissions and access. The disadvantage is that if the ASP service fails, the web service will be impacted as well.
  • Medium (Pooled): this level allocates a pool of memory resources used by all ASP pages. The advantage of the medium level is that you control the amount of resources allocated. In addition, if an ASP page causes the ASP service to fail, it does not affect the web service. The disadvantage is that if one site causes the ASP service to fail, all of the ASP pages will fail.
  • High (Isolated): this level allocates a specific amount of memory resources for each ASP application. The advantage to the high level is that if an ASP page causes the ASP service to fail, only that specific site will fail and not the other sites. The disadvantage is that additional resources are used by each individual application pool.

Hope I helped someone...

Wednesday, 11 April 2007 10:34:41 (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback