ASP.NET


21
Sep 09

HOWTO: Log website errors using exceptions in ASP.NET

Defen­sive pro­gram­ming (ie. check­ing object for null before hav­ing an action on it) can be a great tool but do we always can pre­vent all the errors espe­cially when it comes to user inputs or web servers that not always reli­able. When appli­ca­tion is up and run­ning there are not many ways we can find out that some user had an error unless the error is global so appli­ca­tion goes down. Of course if we have an access to Win­dows Event Viewer on the server we can check it daily but in my hon­est opin­ion Event Viewer is quite hard to use.  Instead of that we can write our own Error­Log­ger. So each time user or server have a bug we will have a nice report on that. For error track­ing we will use .NET built in Excep­tion class and Try and Catch block.

Con­tinue reading →


19
Sep 09

HOWTO: Properly connect to MSSQL database

There are many ways you can con­nect to a data­base in ASP.NET, the way i’m going to explain here based on “try and error” dur­ing my devel­op­ment years. I will try to explain why i do each step and what errors i had in the past so you may pre­vent these in your web appli­ca­tions. Expe­ri­enced pro­gram­mer should know each of these steps and may dis­agree so dis­cus­sion is open to debate.

Con­tinue reading →


18
Sep 09

HttpCombiner modifications for better usability

Http­Com­biner is a HttpHan­dler 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 gen­er­ated files, which makes you web­sites to load faster. You can down­load http han­dler from Microsoft’s web­site by click­ing here and you can read Omar’s arti­cle on how to imple­ment the han­dler here. Orig­i­nal han­dler writ­ten by Omar Al Zabir.

It took me few min­utes to con­fig­ure the han­dler to work, it is easy to use and well doc­u­mented. So i advice you to read Omar’s post before con­tin­u­ing with modifications.

Con­tinue reading →


15
Sep 09

HOWTO: Use C# and VB in the same project

You will get a com­pi­la­tion error if you will place  C# and VB code along in App_Code direc­tory. This lit­tle code snip­pet for web.config gives your com­pliper an abil­ity to dis­tin­guish between lan­guages.  Some of you could ask, i use X lan­guage why should i start an appli­ca­tion with native sup­port for few ? Real life exam­ple explains why would you do that.

Con­tinue reading →


14
Sep 09

HOWTO: Access Session outside of the page’s live cycle

You can­not access Ses­sion object or any other object which resides in page’s life cycle from out of the scope func­tions .This fol­low OOP rules but some­times com­pli­cate devel­op­ment process when you need to access ses­sion from exter­nal source. In this exam­ple i will exam­ine the way i use at any project to hack OOP for my needs. Maybe there is a bet­ter solu­tion but this is the best i’ve found so far.

Con­tinue reading →


9
Sep 09

HOWTO: Limit Viewstate length

In some occa­sions browsers may block or trun­cate  gen­er­ated view­state due to it’s length. This short tweak may solve the issue  by divid­ing the view­state to inde­pen­dent hid­den fields based on the num­ber you pro­vide as value. In this exam­ple max­PageS­tate­Field­Length set to 50 this means when view­state get beyond 50 char­ac­ters it will be bro­ken to dif­fer­ent hid­den fields hold­ing viewstate’s value

Con­tinue reading →