Archive for ASP.NET


.net handler working sequentially and not parallel.

Last week I was working on a .net handler that have many functionalities, that are being triggered from a JavaScript app we have in the company – I realized that the calls to this handler are made sequentially and not parallel as I wold expect.

My first guess was something to do with the application pool’s settings, or some other configuration issue with my iis server, but that direction led nowhere. So I started to look at the code, looking for a lock of some kind, couldn’t find any .. Bad luck.

Than it it me, the handler, in some of it’s methods fetches the logged in users object from the session (only fetches – doesn’t alter in any way) … Hmm what will happen if i’ll drop that IRequireSessionState from the handler ? … And there we go, the handler has returned behaving as I expected – parallel !

Ok, now that I know what is the cause for this problem I made some digging in the web, and found out that I can use IReadOnlySessionState, which will do exactly what I wanted, read things from the session without locking it!


Posted in ASP.NET


Html5 Multiple File Uploading

i got a bit of messing around lately with html and found this great new features to XMLHttpRequest object.
now you can use it to send files and get their progress using javascript ! for all of us this is a great improvment , cause we don’t to use flash / silverlight / java anymore to get a neat progress bar for file upload.
of course there are great solutions (swfupload / uploadify etc) that hides the flash and mimics the whole process , but it not native to the browser …

so the uploader is wrapped as a class named .. you can guess Html5Uploader,
for ease of writing i used jquery – mainly for the selectors and event handling , but it can easily removed by anyone with a bit of javascript knowledge.

so in order to get it up & running create a new html5uploader object using such line :

var uploader = new Html5Uploader({ mimeTypes: “image/jpeg,image/gif,image/png,image/x-png,image/bmp”, queueSizeLimit: 10, fileInputId: ‘filesToUpload’ });
events thrown from the class :

onErrorAddingFile with an error object
onCancel – once a file is removed from queue
onAddedToQueue – once a file being added to queue (here you can write your own html)
onUploadStarted – for each file
onAllComplete – self explained i guess
onProgress – for file upload
onComplete – for each file
onError – on error while uploading.

you can download the demo from this link : html5 multiple file upload source

in the zip file you will find a .net solution with all the files (css/js/ashx) – the upload handler is a .net handler, you can modify one of my previous php upload handlers for this cause if you want to use php as your backend

and view an online demo @ html5 multiple file upload demo

right now chrome and firefox >4 supports html5 uploading, ie – not yet.

if you find this usefull , have any comments – please share with me, it’s nice to listen to my audience :)

Have a good one,



Multiple inheritance in c sharp

Hi there!

all of us .net programmers know that there isn’t a built in way to create multiple inheritance in c#,
well – i needed such. i know some will argue and say this pattern is a no no, and i should have used other methods to create what i wanted,
but for me – it make perfect sense to do so.
am sharing with you the simple way i did so, if it is useful for one of you, i’m glad !

?View Code CSHARP
public class Multiple  where TType1 : new()
where TType2 : new()
static TType1 base1;
static TType2 base2;
public Multiple()
base1 = new TType1();
base2 = new TType2();
public static implicit operator TType1(Multiple c)
{return base1;}
public static implicit operator TType2(Multiple c)
{return base2;}
class Foo{}
class Bar{}
class FooBar : Multiple
//then use as
FooBar foobar=new FooBar();

attached is a visual studio 2010 sample code:



Posted in ASP.NET, c#, ,


linq distinct – create a distinct collection using linq (c#)

Hi there,

well its been a long while since i wrote anything on this blog, alot have changed in this long period.

wanted to share a neat way to use linq in c# to get a distinct list of elements by some key.
lets say you have a collection of categories, where the unique identifier called uid, and you want to make that list distinct,

var practiceAreas = from teamMember in AllTeamMembers
from teamMemberRelation in teamMember.TeamToTeamPracticeAreaRecords
select teamMemberRelation.TeamPracticeArea;
temp = practiceAreas.GroupBy(p => p.EntityId).Select(g => g.First()).ToList();
var categoryCollection = from item in AllItems
select item.Categories;
now make it distinct
var distinctCategoryCollection = categoryCollection .GroupBy(p => p.uid).Select(g => g.First())
neat ha ?
Posted in ASP.NET, c#, linq


flash of unstyled content

have you ever seen a html page that loads unstyled and a second (sometimes more) after it “loads” its gets reorgenized ?
well this problem refered as “flash of unstyled content”.

it happens when the page content starts to load before the css files are completely loaded. you won’t see much of this problem using ie or any other browser other then firefox, thats because the way firefox renders the page is different then the other browsers. it rerender the page every time a new css rule is loaded, ie for example waits for all the page content(includes images) to be loaded and then it plots the rendered result (skipping the FOUC)

ok – so what can be done to avoid this annoing problem ?

i did some research on this issue – trying to find the best solution , and there is no 1 ultimate solution, you will have to optimize your page – reducing the loading size of the page, but more important is moving the css files to the top of your html, acutally to the top of your head section, css files must be loaded first, then the js files and other content.
normally we wont use javascript functions untill the domready event is thrown – so that won’t be a problem.

now, after doing so, we should try to compress the files,
search the web for a css compressor in your preferred language,
examples :

the last one is a great example for combining and compressing the css files,
resulting in 1 css file that holds few files in it.

the same can be done with js files (compressing and mergin)
online js compressing can be done using Yahoo’s YUI Compressor (

or you can search for a php / .net server side js compressor.

Now, after doing these steps your page would weight alot less then it did before – maybe this step already solved your problem.

i would go on and load the images in photoshop and use the save for web method without the max resultion checked.

Hope this article helped you,