This was originally an email I sent to .NET team in my company, then decided to share as a blog post.

The problem:

  • Let’s say you have a complex application, and this application (or part of it) runs very slowly. No bug s in results, no errors or exceptions, but it just so slow! Now you want to know which part of your code is the reason, which method(s) you need to go and modify., which methods take so long to execute or consume so much memory/CPU. How would you know that?
  • Let’s say you want to improve the performance of your application in general (say add caching or such), so, you want to identify which parts of your code deserve your attention and will really make difference (so that you don’t waste your time on optimizing something that will not have big effect in performance), for  example, you might want to identify which methods are called more than others from different parts of your code. How would you do that?

, , , , , , , ,

Click here to go directly to the instructions…

Background (Click above to skip if you know Web Application Projects)

In VS 2002/2003, the web project model for a website was similar to “class library” projects, where you have a .CSPROJ or .VBPROJ file that keeps track of files “included” in the project, and compiles all the pages and controls code behind to a single assembly under “bin”. Each page/control has an automatically generated .DESIGNER.CS or .DESIGNER.VB file, which contains objects mapping to the server controls in the page/control markup (the generation of those files was not always in synch with markup, and that was problematic).

With VS 2005, there was a new “website” model for web projects that compiles each page/control individually as a separate assembly (or each folder, depending on optimization features), and applies this to all files in a given directory and its sub folders. This was a total mess in most “real world” projects, as VS takes so long to build the entire website, and even at deployment, you get sometimes many problems when you have pages that “reference” other pages/controls when IIS it trying to dynamically load the right assemblies to reference, and many other problems.

, , , , ,

This is problematic with ASP.NET AJAX. The main Script Components are NOT sent to the client when in :Legacy” mode. This is “By design” in ASP.NET AJAX, although it is a clear limitation!!

I’m investigating the problem for other solutions and will be sending an update soon.

Thank you, Iman Halawany, for making me note this. I’ve been working on WCF services and ASP.NET MVC stuff lately than normal webforms, so, didn’t realize this obvious showstopper.

To all my readers, I owe you a BIG apology.

The Problem

ASP.NET validators and ValidationSummary controls are rendered as SPAN tags that are shown and hidden based on validation state. The properties of the validators are written normally via JavaScript calls similar to these:


<script type=“text/javascript”>

//<![CDATA[

var Page_ValidationSummaries =  new Array(document.getElementById("vdsSiteLogin"));

, ,

If you have ever thought that the famous if(Page_ClientValidate("validationGroup")) {/*JS Code*/}  and myValidator.ValidationGroup = "validationGroup"; are sure not enough client side capabilities in ASP.NET validators, you are right.

The list of client side API for ASP.NET Validators can be found on this MSDN page "ASP.NET Validation in Depth":

http://msdn.microsoft.com/en-us/library/aa479045.aspx#aspplusvalid_properties

Look for subtitle: "Client-Side APIs".

 

Thanks Simone Chiaretta for mentioning the topic, Mohamed Tayseer for sharing the topic on facebook, and Richard Cook for his comment on the post making me search for the complete list.

, ,

The Problem

In an N-tier application, you keep your logic in a business logic tier, typically a different VS project that can be used from a website, a windows service, or desktop application, and that should be valid to writ unit tests against on its own.

But how about if your requirements say that you need to to upload some file for the business logic to work? Think of a scanned image (signed contract maybe?) or just a comma separated value file containing some emails.  Typically the business logic tier will be the place to to handle this, but how can you send the uploaded file to it? You can get the file as "HttpPostedFile" from the "Request.Files" collection or the file upload control itself, but, to receive it in the business logic, project, the easiest way is to add reference to "System.Web" dll and accept the type "HttpPostedFile" as method argument or so, and when in need to save the file physically, you call the "SaveAs" method of "HttpPostedFile" … So simple right ?

, ,