Saturday, May 10, 2008

ASP.NET - I'm starting to loose love for it!!

I have been swearing by Microsoft Technologies since CA took over Clipper and then dumped it!!! Clipper used to by a bread and butter language for me until 1995 (2 years after CA dumped it). At that time, I had a terrible time on deciding which way to go. Delphi was quite popular and was quite similar to Pascal and then there was VB! I decided that considering Microsoft's might, Microsoft won't easily dump its product. Anyways, Microsoft left its VB coders way behind after VB 6.0. VB.NET was similar but strikingly different as was. It was a new learning but ok - a gradual change. But then there was a promise of platform independence and I was lured by it! Web was getting more and more popular and developing applications in VB.NET seemed to be much faster/ easier than ASP. At-least it was more structured and much more testable with lots of compile time checks. Initially it looked like that continuously increasing build times even for small changes were a small sacrifice in face of structure. However, as I went deeper and deeper it seems that even trivial tasks are not that easy because of Microsoft's decision to take the web development to event driven applications. Numerous times it has happened that it has become difficult to understand what is happening during which event (in the framework) and without a tool such as reflector, it would have been impossible to resolve lots of issues we had in many of the applications. Some of the recent issues I've faced are:
  • URL Rewriting: Ok. It might not really be a .NET thing and IIS thing but unfortunately .NET doesn't run on Apache. Features that apache's mod_rewrite has been providing for so long are still difficult to achieve in IIS.
  • SetMaxAge for caching: Unfortunately, whatever value I set, it sets it to Zero. Refer to http://msmvps.com/blogs/omar/archive/2006/08/02/cache-control-header-cannot-be-set-properly-in-asp-net-2-0-a-solution.aspx
  • Removing a cookie from Cache: I thought it would be easy enough!!! Just set expiry of the cookie to a past date and you should be fine! In fact, I needed to remove all the cookies starting with "custom". The way I went ahead is...


HttpCookieCollection cookies = Request.Cookies;
for(int i=0; i<cookies.Count; i++) {
HttpCookie cookie = cookies[i];
if(cookie.Name.StartsWith("custom") {
cookie.Expiry = DateTime.Now.AddYears(-1);
}
}

  • seems cool? No. turns out that if you modify cookies in Request, it doesn't help. You have a Response.Cookies collection as well. Unless you add a cookie to Response collection, it won't be sent to client and hence client will not know you changed the cookie. Anyways, I added a couple of statements to add cookies in Response collection. Then, another problem. When you add a cookie to Response collection, it gets added to Request collection as well!!! Another issue. So, as many people suggest, I had to take another variable cookieCount before the loop to avoid an endless loop! What a waste of time for simple Cookie manipulation that was so easy in languages such as PHP, ASP etc. etc.
There are lot more things that I'm discovering on daily basis. However, then my biggest worry is about MVC architecture that's becoming a lot more popular in ASP.NET again leaving me wondering how long will Microsoft continue to support the original ASP.NET Page Model? I doubt it'll take long before Microsoft will have to decide the model it wants to support!!

All this has been forcing me to re-think my strategy and look back at PHP, ASP or Ruby on Rails to get sanity back to development as most of the front-ends have actually moved to HTML and JS and these languages just handle the server side manipulation. Wait for a few more days and you might see me changing my framework to PHP!!!

No comments: