Hossein Zahed

Web Developer, Entrepreneur, Software Educator

Limiting number of users accessing asp.net website

What is the best way to limit the number of (concurrent) users accessing a web application that any one can introduce for selling website/application to client and how to increase the number of users accessing it remotely?

If you use the in-process session state management, you can use the HttpApplicationState class, by introducing the Global.asax file and putting something like this in the code behind:

void Application_Start(object sender, EventArgs e)
    Application["ActiveSessions"] = 0;

void Session_Start(object sender, EventArgs e)

    	int activeSessions = (int) Application["ActiveSessions"] + 1;
    	int allowedSessions = 10; // retrieve the threshold here instead

    	Application["ActiveSessions"] = activeSessions;

    	if (activeSessions > allowedSessions)
    		System.Web.HttpContext.Current.Response.Redirect("~/UserLimitReached.aspx", false);

void Session_End(object sender, EventArgs e)
    Application["ActiveSessions"] = (int)Application["ActiveSessions"] - 1;

IEnumerable Vs IQueryable

Many  developers gets confused between IEnumerable and IQueryable. When it comes to writing code, both looks very similar. However there are many difference between them which needs to be taken care of while writing code. Both have some intended usability scenarios for which they are made.

Below lists the differences between them based on their properties :


  IEnumerable  IQueryable
Namespace System.Collections Namespace System.Linq Namespace
Derives from No base interface Derives from IEnumerable
Deferred Execution Supported Supported
Lazy Loading Not Supported Supported
How does it work While querying data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable execute select query on server side with all filters. Hence does less work and becomes fast.
Suitable for LINQ to Object and LINQ to XML queries. LINQ to SQL queries.
Custom Query Doesn’t supports. Supports using CreateQuery and Execute methods.
Extension mehtod
Extension methods supported in IEnumerable takes functional objects. Extension methods supported in IEnumerable takes expression objects i.e. expression tree.
When to use when querying data from in-memory collections like List, Array etc. when querying data from out-memory (like remote database, service) collections.
Best Uses In-memory traversal Paging

The Ultimate List of Freely Available .NET Libraries

A lot of people keep asking about a good list of .net libraries. Hence, we are building this list to save your time and to spread the knowledge.

Some of these libraries will definitely help us developing better solutions. We will do our best to keep updating this list, hope you find this list useful, here we go.



  • Ajax Control Toolkit - Microsoft
  • AJAXNet Pro
  • ASP.NET MVC Project Awesome - a rich set of helpers (controls) that you can use to build highly responsive and interactive Ajax-enabled Web applications. These helpers include Autocomplete, AjaxDropdown, Lookup, Confirm Dialog, Popup Form and Pager. Thanks Omu (April 20, 2011)

Build Tools

  • Prebuild - Generate project files for all VS version, including major IDE's and tools like SharpDevelop, MonoDevelop, NAnt and Autotools
  • Genuilder - Precompiler which lets you transform your source code during the build. Thanks Harry McIntyre (April 13, 2011)



  • PowerCollections - is a library that provides generic collection classes that are not available in the .NET framework. Some of the collections included are the Deque, MultiDictionary, Bag, OrderedBag, OrderedDictionary, Set, OrderedSet, and OrderedMultiDictionary. Thanks Adam Ralph (April 20, 2011)



  • Krypton - Free winform controls. Link fixed (April 14, 2011)
  • Source Grid - A Grid control
  • DevExpress - Over 60 Free Controls from DevExpress. Thanks Florian Standhartinger (April 20, 2011)
  • ObjectListView - is a C# wrapper around a .NET ListView. It makes the ListView much easier to use and provides some neat extra functionality. Thanks Florian Standhartinger (April 20, 2011)

Data Mapper

Dependency Injection/Inversion of Control

Design by Contract


  • SharpDevelop - is a free IDE for C#, VB.NET and Boo projects. Thanks Florian Standhartinger (April 20, 2011).



PDF Creators/Generators

Automated Web Testing

Misc Testing/Qualitysupport/Behavoir Driven Development (BDD)

URL Rewriting

MS Word/Excel Documents Manipulation

  • DocX to create, read, manipulate formatted word documents. Easy syntax, working nicely, actively developed. No Microsoft Office necessary.
  • Excel XML Writer allows creation of .XLS (Excel) files. No Microsoft Office necessary. Been a while since it has been updated. It also provides code generator to create code from already created XLS file (saved as xml). Haven't tested this but looks very promising. Too bad author is long time gone.
  • Excel Reader allows creation/reading of .XLS (Excel) files. No Microsoft Office necessary. Been a while since it has been updated.
  • Excel Package allows creation/reading of .XLSX (Excel 2007) files. No Microsoft Office necessary. Author is gone so it's out of date.
  • EPPlus is based on Excel Package and allows creation/reading of .XLSX (Excel 2007). It is actually the most advanced even comparing to NPOI.
  • NPOI is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project which can help you read/write xls, doc, ppt files.
  • sharp2word - a Word 2003 XML Documents Generator from C# code without any components or libraries. Thanks dublicator (April 20, 2011)
  • ClosedXML - an actively developed library for generating OpenXML Excel files. Thanks Joseph Robichaud (April 26, 2011)


  • sharpserializer - xml/binary serializer for wpf, asp.net and silverlight
  • Protobuf.NET - fastest serialization port protobuf format into .NET platform. Thanks slava pocheptsov (April 26, 2011)


Social Media

  • LinqToTwitter - Linq-based wrapper for all Twitter API functionality in C#
  • Facebook C# SDK - A toolkit for creating facebook applications / integrating websites with Facebook using the new Graph API or the old rest API.

Package managers for external libraries

  • NuGet (formerly known as NuPack) - Microsoft (developer-focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development)
  • OpenWrap - Sebastien Lambla - Open Source Dependency Manager for .net applications

Unit Testing/Mocking



  • Smart Thread Pool - Thread Pool management library
  • Retlang - a high performance C# threading library. Thanks MarcBot (April 13, 2011)
  • bbv.Common - an open source library of software components that makes building multi-threaded, event-based and loosely coupled systems easy. Thanks Urs Enzler (April 14, 2011)
  • PowerThreading - a llibrary (DLL) containing many classes to help with threading and asynchronous programming. Thanks Adam Ralph (April 20, 2011)


  • CSLA Framework - Business Objects Framework
  • AForge.net - AI, computer vision, genetic algorithms, machine learning
  • Prism - Composit UI application block for WPF, Silverlight and WP7 - Microsoft patterns & practices
  • Enterprise Library 5.0 - Logging, Exception Management, Caching, Cryptography, Data Access, Validation, Security, Policy Injection - Microsoft patterns & practices
  • File helpers library
  • C5 Collections - Collections for .NET
  • Quartz.NET - Enterprise Job Scheduler for .NET Platform
  • MiscUtil - Utilities by Jon Skeet
  • Noda Time - DateTime replacement (idomatic port of Joda Time from Java)
  • Lucene.net - Text indexing and searching
  • Json.NET - Linq over JSON
  • Flee - expression evaluator
  • PostSharp - AOP
  • IKVM - brings the extensive world of Java libraries to .NET.
  • C# Webserver - Embeddable webserver
  • Long Path - Microsoft
  • .NET Engines for the GOLD Parsing System
  • NCQRS - library for event-driven architectures (CQRS).
  • Reactive Extensions for .NET - a library for composing asynchronous and event-based programs using observable collections. Thanks steve (April 14, 2011)
  • Mono.GameMath - a project to develop a highly-performant math library for games, based on XNA APIs. Thanks Alex Rønne Petersen (April 14, 2011)
  • SLSharp - a runtime IL-to-GLSL translation engine, allowing people to write GLSL shaders as C# code. Thanks Alex Rønne Petersen (April 14, 2011)
  • InfusionSoftDotNet - a dll to ease the pain for .Net developers to access the InfusionSoft API. Thanks Michael Gibbs (April 20, 2011)
  • re-mix - provides mixins for C# and Visual Basic .NET. Thanks Stefan Papp(April 20, 2011)
  • Mono.Cecil - a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. It has full support for generics, and support some debugging symbol format. Thanks Florian Standhartinger(April 20, 2011)
  • ImapX - is an modern .NET 2.0 library for management of IMAP folders, supports SSL Connection and different IMAP formats, such as Gmail IMAP, AOL IMAP (November 30, 2011)

Get Different Values from URL in ASP.NET

You may at times need to get different values from URL.

Below example shows different ways of extracting different parts of URL




Response.Write("<br/> " + HttpContext.Current.Request.Url.Host);
Response.Write("<br/> " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("<br/> " + HttpContext.Current.Request.ApplicationPath);
Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("<br/> " + HttpContext.Current.Request.Url.PathAndQuery);