Defensive programming (ie. checking object for null before having an action on it) can be a great tool but do we always can prevent all the errors especially when it comes to user inputs or web servers that not always reliable. When application is up and running there are not many ways we can find out that some user had an error unless the error is global so application goes down. Of course if we have an access to Windows Event Viewer on the server we can check it daily but in my honest opinion Event Viewer is quite hard to use. Instead of that we can write our own ErrorLogger. So each time user or server have a bug we will have a nice report on that. For error tracking we will use .NET built in Exception class and Try and Catch block.
ASP.NET
19
Sep 09
HOWTO: Properly connect to MSSQL database
There are many ways you can connect to a database in ASP.NET, the way i’m going to explain here based on “try and error” during my development years. I will try to explain why i do each step and what errors i had in the past so you may prevent these in your web applications. Experienced programmer should know each of these steps and may disagree so discussion is open to debate.
18
Sep 09
HttpCombiner modifications for better usability
HttpCombiner is a HttpHandler allows you to gather all css and js files together which decreases amount of http requests made to server when user requests a page and also to cache the generated files, which makes you websites to load faster. You can download http handler from Microsoft’s website by clicking here and you can read Omar’s article on how to implement the handler here. Original handler written by Omar Al Zabir.
It took me few minutes to configure the handler to work, it is easy to use and well documented. So i advice you to read Omar’s post before continuing with modifications.
15
Sep 09
HOWTO: Use C# and VB in the same project
You will get a compilation error if you will place C# and VB code along in App_Code directory. This little code snippet for web.config gives your compliper an ability to distinguish between languages. Some of you could ask, i use X language why should i start an application with native support for few ? Real life example explains why would you do that.
14
Sep 09
HOWTO: Access Session outside of the page’s live cycle
You cannot access Session object or any other object which resides in page’s life cycle from out of the scope functions .This follow OOP rules but sometimes complicate development process when you need to access session from external source. In this example i will examine the way i use at any project to hack OOP for my needs. Maybe there is a better solution but this is the best i’ve found so far.
9
Sep 09
HOWTO: Limit Viewstate length
In some occasions browsers may block or truncate generated viewstate due to it’s length. This short tweak may solve the issue by dividing the viewstate to independent hidden fields based on the number you provide as value. In this example maxPageStateFieldLength set to 50 this means when viewstate get beyond 50 characters it will be broken to different hidden fields holding viewstate’s value