How to get Microsoft certification?

Challenge:

Since last couple of weeks, few friends asked me that how can they get Microsoft certification? Any tips and tricks? I replied to them via email or any other source. But as per Scott’s formula [“You have a finite number of keystrokes left in your hands before you die.” – http://keysleft.com/], rather than replying to email write a blog on it. And share the link. So, next time if someone asks same question to me [Or may be you] Can send this blog’s link.

Solution:

So long back — I wrote Microsoft certification quick start guide
This document is a best place to start! Few things have been changed. But the basics remains the same.
If you don’t have time to go through the document, and need a quick summary. here you go!

  1. Target one exam at a time. Visit each exam’s Home Page – Understand what this exam covers. And start preparing. Best way to prepare for MS Certification is MS Press Books. You can find it from each of the following link – Better to have a hard copy. For example you are aiming to give 70-480 exam. It’s exam detail page is here : https://www.microsoft.com/learning/en-in/exam-70-480.aspx check “Skills Measured” section to understand what this exam covers. Check “Preparation options” section for all resources related to this exam.
  2. Select your exam track from here : https://www.microsoft.com/learning/en-in/certification-overview.aspx for example if you are ASP.NET Web Developer then you should go for this track : https://www.microsoft.com/learning/en-in/mcsd-web-apps-certification.aspx
  3. Before you go for exams. Start giving exams from Dumps, Search for your exam. E.g. http://www.examcollection.com/70-480.html there will be the lot of dumps. But I follow this formula to select a best dump [You will need a VCE Software to run this VCE files]:
    1. Select a dump – Which has MOST number of questions
    2. And which got Max number of votes. So, as per this example it goes for Microsoft.Actualtests.70-480.v2013-12-31.by.MARY.169q.vce
      [As it got 169 questions and 162 votes]
  4. Then book your exam slot, Pearson is best!
  5. All the best for your exams!

Happy Certification! 🙂

Basics for .NET beginner developers

Challenge:

Luckily, I’ve been crafting on .NET since last 7+ years. Initially I learnt .NET in college. And then after explored it further during my professional career. Some time back few of my friends asked me, How can they also learn .NET? Which are the best resources to begin with? And then be a .NET Ninja!
You are also learning .NET? Or would like to start learning .NET? Or you work on .NET. But would like to brush up your fundamentals? Then this post is for you!

Solution:

Start with following links :
http://www.pragimtech.com/c-sharp-video-tutorials.aspx
http://www.pragimtech.com/Free-aspnet-video-tutorial.aspx
https://www.youtube.com/playlist?list=PL8598C97BA1D871C1&feature=view_all
https://www.youtube.com/playlist?list=PLAC325451207E3105&feature=view_all
Then move to this :
http://www.learnvisualstudio.net/free/c-training/
http://www.itorian.com/2012/08/LearnDotNet60days.html
http://www.youtube.com/watch?v=W3lHQdoYsUo&list=PL0BB0AD0F12A24B6E
http://en.wikipedia.org/wiki/Common_Language_Runtime
http://en.wikipedia.org/wiki/.NET_Framework
http://www.codeproject.com/Articles/20694/Net-Framework
http://www.codeproject.com/Articles/3992/What-is-NET
http://www.c-sharpcorner.com/uploadfile/puranindia/net-framework-and-architecture/
http://www.completecsharptutorial.com/basic/parameter-examples.php
http://www.microsoftvirtualacademy.com/training-topics/c-app-development
http://www.microsoftvirtualacademy.com/training-courses/c-fundamentals-for-absolute-beginners
http://quickstarts.asp.net/QuickStartv20/default.aspx
http://www.microsoftvirtualacademy.com/training-courses/software-developmentfundamentals#?
fbid=-dwjFvfio5-
– http://www.microsoftvirtualacademy.com/training-courses/database-fundamentals#?fbid=-
dwjFvfio5-
Please note Programming is like swimming. You need to delve in to it. To be a master of it. So, most of the above resources are videos. But would strongly recommend you that. Do practice after watching each video!And here are
And here are some exercises for you:

  1. Create a console application which takes user name as an Input and tells moon sign – as per his/her input
  2. Create a console application which takes a Number – for which user would like to print a Multiplication Table
  3. Anything else?

Few nice to read books:

  1. CLR Via C#
  2. MCTS 70-536 Self-Paced Training Kit – Application Development Foundation
  3. Murach’s ASP.NET

Please remember you can’t be master of .NET/any field over the night. As per research it takes 10,000 hours of deliberate practice to be master of any field. So, have lot of patience. Practice as much as you can! — The harder you practice, the luckier you get!
Also, If possible give Microsoft certification exams — Here is Certification Quick start guide for you!
If you know any other .NET resource, which you think is excellent. And should go in this list. Then please do share it with others via comment!
Happy Programming! 🙂

Dark vs Light Visual Studio Theme

Challenge:

This post is Not on any Technical Coding concept. But it is on Visual Studio – Lifeline of  all .NET Developers! You might think a post on Theme? Sounds funny?! But If you are a developer then you spent most of your time looking at your monitor and mostly Visual Studio! And few developers who are passionate about Code. Might do Code till midnight. In dim light! 🙂 (Yes, I am talking about you!)
If you have following questions:

  1. Why lot of Developers started using Dark theme of Visual Studio?
  2. What should I use Dark or Light theme?
  3. Why should I use Dark theme?

Then this post is for you!

Solution:

I noticed that lot of people have stated using Dark Theme of Visual Studio. I never thought I should try that. But people whom I admire and follow started using that. And I also thought to change it. When I changed it first time.  Haven’t liked it [You know ComfortZone!?] So, rolled back it, But after few days. Don’t know why thought o re-try it. And after that I never thought I should go back to light theme. I am enjoying Dark theme of Visual Studio.
I was just curious to know what people across the Globe uses and recommend. And for that did a quick search and found following articles. Which are really good to read:

  1. http://www.hanselman.com/blog/ChangingYourColorsInVisualStudioNETBlackVersusWhite.aspx
  2. http://weblogs.asp.net/infinitiesloop/Join-the-Dark-Side-of-Visual-Studio
  3. http://ux.stackexchange.com/questions/8153/what-are-the-negative-and-positive-aspects-of-dark-color-scheme

Few excerpts:
The default scheme sports a bright white background color with dark text over it. But monitors these days are brighter than ever. You’re presumably a programmer, so you’ve no doubt had those late but productive coding nights, nights that are lit by only the glow of your monitor. The glow is bright enough to light up the room and cast shadows. Not unlike… a light bulb.
So there you are, staring straight into a strong light source, looking for the few pixels on it which are not illuminated. Can you read the wattage and manufacturer letters on the head a light bulb while it’s turned on? Ahhh… but what if the bulb were black, and only the letters on it were illuminated?
Another benefit someone pointed out to me once — if you’re on a laptop, it saves your battery life! Horray for an extra 20 minutes of mobile coding!
It seems to me the only reason a black-on-white background is so standard is because the GUI was invented to be an analogy to pen and paper. Paper is white. Your screen doesn’t have to be. Don’t conform to the status quo! Plus, it just looks really cool… I think.

Other links:

http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx
So, Which Color Theme you were using before reading this blog post? And which you will use after reading this blog post? What’s your Visual Studio environment settings?
Happy Coding! 🙂

Error while using Cascading DropDownList with AjaxControlToolkit

Challenge:

While Implementing Cascading drop down we faced following error:
Error: Error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using in configuration or <%@ Page EnableEventValidation=”true” %> in a page.
For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Source File: http://OURHOSTNAME/ScriptResource.axd?d=3VKrK_7HFd3y9jouIWGfT0xsPUpPWsWH7SoDffy51nkCL04Nc90n7Ein_H4RztbD1yDGLUI-Zz15U7kAewqh2RASTjlbBKaWvjs5uaWOHUtXwDXAq22ilJZaUX8Iu9W_HK9ITwo1waG12DLEuDRxogn2m-XmlhYYCX-66L12c6NnjBet1rAqn3G588BxLbc40&t=348b0da
Line: 1534
Yes, you are right. Our DropDownLists were wrapped within Update Panel. You are also facing similar error? Then this post is for you:

Solution:

We did a quick search and found following links:
http://ajaxcontroltoolkit.codeplex.com/workitem/8103
http://forums.asp.net/t/1903036.aspx?how+to+set+EnableEventValidation+false+from+userControl+DotNetNuke
From Link what we understood is that, It is a BUG of AjaxControlToolkit and to resolve  this you’ve to try following workaround:
[sourcecode language=”csharp”]
protected void Page_Init(object sender, EventArgs e)<br clear="none" />        {        <br clear="none" />            Page.EnableEventValidation = false;<br clear="none" />        }
[/sourcecode]
So, Just use this code where you are facing this challenge. We were seeing it from one of the Sublayout. So, we kept it there and it worked!
Happy Coding! 🙂

Country specific phone number validation with ASP.NET

Challenge:

Before few weeks back, I have been assigned a task, Where I need to validate a phone number. Sound simple? Yes it is! But I needed to do it country specific? Now, how it sounds?
Basically, User will have a list of countries to select. And based on his/her country selection he/she will provide phone number and we should validate based on country selection. Sounds challenging? That’s how life should be!
You are also working on such thing and looking for a way to get out of it? Then this post is for you!

Solution:

As per every software engineer’s practice, I started my research and our common friend. Google presented option of using Regex for each country. But it sounded bit complex to me. Then continued my research and found a super hero!
LibPhoneNumberIt’s a library from Google champs to validate phone number (Excerpt from their main page — Google’s common Java, C++ and Javascript library for parsing, formatting, storing and validating international phone numbers. The Java version is optimized for running on smartphones, and is used by the Android framework since 4.0 (Ice Cream Sandwich).)
And after reading this description, It attracted me! (To you as well?). It’s good we found HERO. But how to fit him in our picture? Then after doing bit of a research found this two nice components:

  1. http://phoneformat.com/ — Javascript version of Google’s libphonenumber library
  2. http://libphonenumber.codeplex.com/ – C# port of Google’s libphonenumber

This was a Eureka moment. Just plugged both of this libraries with CustomValidator and you are done! So, here’s how CustomValidator clientside and server-side functions looks like:
Blogs
SUGIN
[sourcecode language=”html”]
<asp:<span class="hiddenSpellError">TextBox ID="txtPhone"  runat="server" />
<asp:<span class="hiddenSpellError">RequiredFieldValidator ID="reqTxtPhone"
runat="server" ErrorMessage="Please enter a phone number" Text="*" ControlToValidate="txtPhone"
></asp:RequiredFieldValidator>
<asp:<span class="hiddenSpellError">CustomValidator ID="custPhoneNumber" runat="server"
OnServerValidate="PhoneNumberValidate"
ErrorMessage="Please enter valid phone number"
Text="*"
ControlToValidate="txtPhone"
ClientValidationFunction="PhoneNumberValidate"
/>
[/sourcecode]

[sourcecode language=”javascript”]
/*
This function will be used to validate
Phone Number client side by CustomValidator
*/
function PhoneNumberValidate(oSrc,args) {
// Call PhoneFormat.JS function which takes Phone Number and Country Code
// in ISO 3166-1 format
var isValidNumberOrNot = isValidNumber(txtPhone.value, ddlcountry.value);
arg.IsValid = isValidNumberOrNot;
}
[/sourcecode]
[sourcecode language=”csharp”]
/// <summary>
/// This function will be used to validate
/// Phone Number server side by CustomValidator
/// </summary>
/// <param name="source">Source</param>
/// <param name="args">Arguments</param>
protected void PhoneNumberValidate(object source, ServerValidateEventArgs args)
{
PhoneNumberUtil phoneUtil = PhoneNumberUtil.Instance;
// TODO : EXCEPTION HANDLING
string countryCode = ddlcountry.SelectedItem.Value
if (string.IsNullOrEmpty(countryCode))
{
args.IsValid = false;
}
else
{
PhoneNumber phoneNumber = phoneUtil.Parse(txtPhone.Text, countryCode);
bool isValidNumber = phoneNumber.IsValidNumber;
args.IsValid = isValidNumber;
}
}
</span></span></span>
[/sourcecode]
Just a note : LibPhoneNumber accepts country code in ISO 3166-1 format. But if you’ve drop down Text and Value both in full form e.g. “India” and you need to pass it as “IN” and If it’s not possible to do any change at your DropDown value level then you can use function, Which has been submitted at — https://github.com/albeebe/phoneformat.js/issues/9 It converts CountryName to CountryCode
Happy Phone Number Validation! 🙂

Bootstrap with ASP.NET Basics and learnings

Challenge:

Howdy Folks, Sorry for being away from you for so long. But was occupied with lot of other things. But now, I’m here to share my learnings with you.
Before couple of weeks back, I’ve to create one functionality to make user’s task easy. I was clear with back-end code. And to make UI intuitive, I thought to use Bootstrap (If you are new to bootstrap, then I would recommend you to take a moment and give it a read here : http://en.wikipedia.org/wiki/Bootstrap_%28front-end_framework%29 and http://getbootstrap.com/)
Long story short, Bootstrap is a framework for creating UI more intuitive rapidly! Developed by Twitter champs!
And If you know Bootstrap, you must be knowing that how easy it is to integrate bootstrap with your application. And yes, you are right it is. But while working on it, I found few challenges and learnt something which I thought to share with you!
Let’s go!

Solution:

If you are new to bootstrap, and looking for a way to integrate it with your ASP.NET application, then following are a good read to do so:
If you are using VS 2013 then you don’t have to worry. Because MS guys has integrated bootstrap within it.
http://techcrunch.com/2013/06/27/microsoft-adds-bootstrap-support-to-visual-studio-2013/
http://www.asp.net/visual-studio/overview/2013/creating-web-projects-in-visual-studio#bootstrap
But if you are using VS < 2013 then this posts will surely help you:
http://geekswithblogs.net/JeremyMorgan/archive/2012/09/18/how-to-use-twitter-bootstrap-on-an-asp.net-website.aspx
http://www.mytecbits.com/microsoft/dot-net/bootstrap-3-0-0-with-asp-net-web-forms
http://elbruno.com/2013/10/02/vs2013-howto-create-a-website-project-in-visual-studio-using-bootstrap/
So, have you tried it? Looks simple, Correct? Till this point of time, everything was simple. But Life is not as simple as it seems to be!
So here are my learnings:

  1. Dismissable alerts : When I tried to use it (http://getbootstrap.com/components/#alerts-dismissable). It didn’t worked. Then figured out that it needs Jquery reference on a page. So, If you are facing same challenge, give it a try! Or if you are going to use first time, don’t do such mistake 🙂
  2. Modal : The default example of Modal given in documentation, didn’t worked for me. Then this tutorial helped me : http://www.w3resource.com/twitter-bootstrap/modals-tutorial.php
  3. Width of Modal Dialog : If you would like to change width of a modal dialog then here’s a way to do it: http://stackoverflow.com/questions/10169432/how-can-i-change-the-default-width-of-a-twitter-bootstrap-modal-box
  4. RequiredFieldValidation and Validation and State : Wanted to apply styling as shown here: http://getbootstrap.com/css/#forms-control-validation

Initially tried with RequiredFieldValidator. But due to it’s complexity avoided doing so. Then used CustomValidator, Here’s how ClientValidationFunction function looks like:
[sourcecode language=”javascript”]
function ValidateALTText(oSrc, args) {
var isValid = false;
// label label-warning
isValid = args.Value.trim();
if (isValid) {
$("#" + oSrc.id).prev(".form-control").parent().removeClass("has-error");
}
else {
$("#" + oSrc.id).prev(".form-control").parent().addClass("has-error");
}
args.IsValid = isValid;
}
[/sourcecode]

  1. Jquery Plugins : Cool, Jquey Plugins which has been designed to use with Bootstrap
    1. Wizard : Would like to create Wizard? http://vadimg.com/twitter-bootstrap-wizard-example/
    2. Confirm, Alert, Custom Dialog : If you would like to take a confirmation from user before doing postback then go for http://bootboxjs.com and if you are facing issue while showing confirmation box and doing postback then this thread will surely help you : http://stackoverflow.com/questions/20389205/bootbox-with-jquery-and-bootstrap-with-a-net-page-no-working/21433099#21433099
    3. FileStyle : Change look and feel of your file input box : http://markusslima.github.io/bootstrap-filestyle/

Found it useful? You have your own set of learnings? Why don’t you share it with all of us?
Happy Bootstraping! 🙂
Good reads:

  1. Twitter Bootstrap Tutorial : http://www.w3resource.com/twitter-bootstrap/tutorial.php
  2. The original list of resources and plugins for Bootstrap : http://bootsnipp.com/resources

 

ASP.NET Application from where CultureInfo.CurrentCulture reads culture?

Challenge:

Before couple of weeks back, we spent the good amount of time figuring out from where an ASP.NET reads CultureInfo.CurrentCulture settings? Why? Because for one of our application it was English – UK and we wanted to change it to English – US.
Yes, we can modify it globally using web.config by setting [globalization culture=”en-US”]. But it will apply to whole application, Yes, you are right we can apply it on page as well. But it was working fine on our live server without configuration change either on page/config. And we wanted to know why? [Sometime rather than finding a solution, It’s good to find out a root cause]
We did a lot of read and finally, we fixed it and found the root cause. What, you are also searching for the same? Eager to know from where it reads? let’s go

Solution:

To reproduce the issue, you can do following test scenario:

  1. Print “System.Globalization.CultureInfo.CurrentCulture” in a command prompt application
  2. Do the same in ASP.NET page — Simple Response.Write on sample page should do. [Make sure your site is hosted under IIS and running as NETWORK SERVICE user, same as live scenario]
  3. Now run both samples and note your CultureInfo
  4. Now, from Regional Settings do change your Culture settings.
  5. Repeat step#3

Analyzed the results? Surprised? Your changes will get reflected in console application. But not in ASP.NET application. Why?
We did a quick search and following thread came up :
http://stackoverflow.com/questions/9697604/from-where-cultureinfo-currentculture-reads-culture
As this thread says it reads it from System definitions

No matter what browser is in use, the definition for System.Globalization will always come from the Operating System definition

But our simple test says, it’s not true correct? Then from where it comes?
Also, did a quick search and found following thread:
http://stackoverflow.com/questions/14322910/cultureinfo-values-differ-between-applications-for-the-same-culture-is-this-a-b/14323336#14323336
And it did a trick!

Jason Evans’s comment pointed me in the right direction. See the link he posted: ASP.NET application doesn’t reflect Regional settings
It turns out that regional settings are stored per user in Windows. This is something I should have been aware of. Updating the application pool to run as myself produced the same result across both applications.
To be fair, what is still confusing is how Network Service (the account the application pool was running under) came to have the incorrect value. I’m not even sure how I’d rectify that.
Edit:
If you need to update the regional settings for reserved accounts. You have two options.

  1. Control Panel > Regional Settings > Click the administrative tab and then select “Copy Settings”. On the screen that launches, ensure you check “Welcome Screen and system accounts”. Older versions of Windows are similar I believe.
  2. For the brace. Registry: HKEY_USERS > SID… > Control Panel > International. The security identifier for Network Service is: SID: S-1-5-20.

Ensure you restart the application pool for settings to take effect.

We followed approach#1, and it worked for us! [This is how it looks like!]
CultureInfo-DateTimeSettings
In summary, our ASP.NET application was running under NETWORK SERVICE user, and we were trying to change Regional settings for current logged in user and NOT Network Service user.
Happy Coding! 🙂

ASP.NET Website Performance Basics – Part 2

Challenge:

Recap : In last part of ASP.NET Website performance basics, Dax shared basic methodology of troubleshooting ASP.NET Website performance challenges!
Where he shared, what all things we need to do, and why we should do it (Remember W-W-H theory?). And just pointers of How to do it! And as Dax promised, that he will help us to understand how part more [We all know, how well Dax keeps his promises! :)] and here he is.
In this post [Would also name it “ASP.NET Basics”], we will look at following things (Which are very IMP. to diagnose performance issues):

  1. When you open any website from your browser, what all happens, behind the scenes? — Not related to ASP.NET just basics, how it reaches till your ASP.NET Application
  2. Now, we’ve reached to ASP.NET Application, after that we will look at — ASP.NET Application LifeCycle — All about — HttpApplication,HttpContext,HttpRuntime, HttpModules etc.
  3. Request Queuing
  4. Major Performance killers ( Hanging Requests, Session can slowdown your application — Thread Agility Issue, Exceptions and performance co-relation, MaxConnections, High GC, Contentions, App Pool Recycle, Memory leak)

Above topics sounds similar? Very Basic? (Back to Basics, Stick to basics. Because a basic always works!) But still unknown? (During our interview sessions, we ask these questions to most of our candidate, And so less can answer it)Don’t worry, we will learn it, So, as Dax and his team!
Here we go!

Solution:

When you open any website from your browser, what all happens, behind the scenes?

You might know this question or learnt it during your college days. And If you are pretty much confident you know this you can skip it. But Dax recommends that even though you know it. It would be a good idea to brush up this stuff.
Because while working on performance stuff, you need to know about everything starting from Client’s Browser, DNS, Firewall, Switch — You no need to be expert in this subject. But when you troubleshoot it, You should know all these players very well.
My favorite — one is from MCTS 70-528 exam book – Chapter1-Lesson1 – Understanding the PlayersMajor-Players
Another good articles:
http://www.codeproject.com/Articles/121096/Web-Server-and-ASP-NET-Application-Life-Cycle-in-D
http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle

Good to remember about M-H-P-M

http://www.codeproject.com/Articles/87316/A-walkthrough-to-Application-State
Thanks a lot to author of above articles. It clarifies everything. So, now you know what all happens — from browser till server — a request goes through a journey and then gets served!
Here you must’ve seen about HttpApplication object, this guy is very critical while serving your requests.  HttpApplication consists of HttpModules.
index
 
http://blog.andreloker.de/post/2008/05/HttpApplication-instances.aspx
HttpApplication Gotchas:

  1. ASP.NET may instantiate many instances of HttpApplication as required (. In fact, it will create an instance of the class for each request that is handled in parallel on the server.
  2. “ASP.NET maintains a pool of HttpApplication instances over the course of a Web application’s lifetime. ASP.NET automatically assigns one of these instances to process each incoming HTTP request that is received by the application. The particular HttpApplication instance assigned is responsible for managing the entire lifetime of the request and is reused only after the request has been completed. This means that user code within the HttpApplication does not need to be reentrant.”
  3. You can observe asp.net pipeline instance count in the performance counters to see how many instances of your HttpApplication class are pooled at the moment.
  4. In Integrated Application mode — HttpApplication will called once during application initialization and another during the first request
  5. When ASP.NET Creates Instance of the HttpApplication class that represents your application, instance of any odules that have been registered are created. When a Module is created, its Init method is called and the module initializes itself. — and the custom module will run for all resource handler, even though resource handler is not an ASP.NET handler
  6. If you see More number of requests [You can check it via IIS log or performance counter] and Heavy HttpApplication Instances is Normal, Because it means that current HttpApplication Pool was not enough and ASP.NET need to spawn worker processes.
  7. But if you see less number of requests, and still see heavy HttpApplication instances then it is abnormal. We need to find out slow pages/handlers etc.
  8. ASP.NET run-time keeps two pools of HttpApplication objects. First is a special pool with HttpApplication objects used for application level events (such as Application_Start, Application_End), Second pool contains instances used in requests to serve all other types of events
  9. Try this out — http://lowleveldesign.wordpress.com/2011/07/20/global-asax-in-asp-net/
  10. HttpApplication Events

HttpApplication-Events
Other good reads:

Huh! Load of things, correct? Useful? Dax says these information is really useful and it will clarify your understanding more on ASP.NET internals!

Request Queuing

It is really good to know about Request Queuing, lot of us already know about Request Queuing — Simple, a Request is queuing. Yes, my dear friend you are right. But there are different level of Queuing happens. And untill and unless you know your request is queued at which level, it won’t be easy to fix it!
Great post! — http://blog.leansentry.com/2013/07/all-about-iis-asp-net-request-queues/
Basically, Request Queuing can happen at mainly 4 levels:

  1. HTTP.SYS: Application pool queue
  2. IIS worker process: completion port
  3. ASP.NET: CLR threadpool queue
  4. ASP.NET: Integrated mode global queue
  5. [OR]ASP.NET: Classic mode application queue

Request_Timeline2 Req-Q
Source — http://fullsocrates.wordpress.com/2013/02/28/asp-net-threadstuning-thread-parameters-12-2/
To diagnose, your level of Queuing. Best thing is performance counters [Dax, is going to share more on performance counters in his upcoming posts] and once found you can use tools like FRT, Dump analysis etc. to find a main bottleneck [Yes, Yes — Dax will post on these topics in future for you!]

Major Performance Killers

  1. Application Pool Recycle/Crash — If your application pool is crashing is or recycling [How Can I check that? You can check EventLog OR if your application got log do log entry [Just a note : Application_End will not get called, when your application crashed unexpectedly a.k.a. Crash] — see — http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx] periodically than it’s not good for your application’s health. Because when application pool gets recycled everything in memory [Session/Cache/Static/Application objects] gets lost, and your application need to server everything from Database and rebuild cache. You can solve this issue by checking EventLog and Configuring+Analyzing Crash Dump.http://kiranpatils.wordpress.com/2012/06/20/is-it-necessary-to-recycle-worker-process-periodically/ and http://kiranpatils.wordpress.com/2010/05/25/goo-to-know-on-asp-net-application-restarts/
  2. Hanging Requests — Your users are complaining that the site is loading slowly. Requests to your application are hanging. With so many possible causes of request hangs, its difficult to know where to even start. — http://mvolo.com/troubleshoot-iis-hanging-requests/
  3. Exceptions, handle them gracefully — Exceptions can slowdown your application. Because when your application throws an exception — It Creates objects — CLR needs to do object allocation — And after that GC for those allocation! [Analyze your application logs to see exceptions, and handle them gracefully] — http://blogs.msdn.com/b/tess/archive/2005/11/30/498297.aspx
  4. %Time in GC — When this time is high, your requests will get paused for a while and your end users will see slow response time during this time. If it is >=10% then you need to dig in to this issue.  Also, check for Memory Leak — http://kiranpatils.wordpress.com/2012/06/05/basics-of-memory-leak/
  5. Contentions — If your CPU is not being utilized and you still see low throughput, you may be suffering from high contention rate. Means your code has lock on shared resources, which is taking time to process, and due to this other requests are going in Queue. Simple concept in locking — “Acquire lock as late as possible, and release it as soon as possible” http://kiranpatils.wordpress.com/2013/01/13/thread-synchronization-basics/
  6. Session lock – Thread agility issue Disable session for the pages/handlers, where you don’t need them. https://github.com/angieslist/AL-Redis http://stackoverflow.com/questions/3629709/i-just-discovered-why-all-asp-net-websites-are-slow-and-i-am-trying-to-work-out
    http://stackoverflow.com/questions/8068925/redis-backed-asp-net-sessionstate-provider

Good to read resources:

  1. http://msdn.microsoft.com/en-us/library/ff647787.aspx
  2. Most recommended — https://www.leansentry.com/try#course
  3. http://blogs.msdn.com/b/mcsuksoldev/archive/2011/01/19/common-performance-issues-on-asp-net-web-sites.aspx
  4. http://www.codeproject.com/Articles/23306/10-ASP-NET-Performance-and-Scalability-Secrets
  5. http://blog.leansentry.com/2013/07/the-server-logs-you-need-to-know-to-fix-any-iis-aspnet-error/
  6. http://mvolo.com/fix-the-3-high-cpu-performance-problems-for-iis-aspnet-apps/

Sorry for such a long post. But It’s good to clarify basics. Because once it is clear, you can fix any issue!
These are the common performance killers, In upcoming posts, we will see how to diagnose them! Till than Happy Performance Tunning! 🙂
 

ASP.NET Website Performance Basics

Challenge:

In a small city, there lived a developer named as Dax. And his boss name was Gabe. Their main goal was to develop a faster running websites and have happy clients! (So, as you!?) And they were best in the town to deliver faster running websites!
One fine morning, they faced a challenge. And this blog post is about how they overcome that challenge.

Disclaimer — All characters in this publication are entirely fictitious and any resemblance to real persons, living or dead, is purely coincidental.

Solution:

Read it from left to right
Basics-1 Basics-22
Gabe asked Dax to fix, their ASP.NET website performance issue and while working on it, Dax made a mistake, which most of us (Including me) make, it is fixing a performance issue by blindly guessing the things along with worse part, making code change which “they think”  it is causing slowness! But this “stab in the dark” method doesn’t work most of the time! [Just a note : I believe that don’t fix any issue, until and unless you’ve reproduced it or understood it thoroughly, If you do it without understanding it, you never know when it will come back to you! But surely, it will!]
Y’day night Dax, sent me an e-mail and asked to share his and his team’s performance learnings with you! [You know, Jesus requested him to share his learnings with you? How honest, Dax is!]
Whatever stuff, you work on, If you follow W (What)- W (Why)- H (How) theory you can solve anything!

What are Website Performance standards?

Have seen lot of people who work on performance issues, without having a measures [Statistics and numbers are your best friends while working on performance! Because if you can’t measure anything, you haven’t improved it yet!]. How fast is really fast? [Carpentry quote : Measure twice, cut once!]
So, here are some numbers, which Dax came across while doing research and reading on website performance standards blogs and articles:
Before, we move on, let’s have a look at, good to know terminologies:

  1. Response time of your server : The time taken, by server to process your request, it includes time taken by Database call, File IO Operation, Time taken by .NET CLR, Request Queuing etc.
  2. TTFB : Time to load first byte, this is the time when browser requests HTML of your page, and server builds your whole page’s HTML to browser, and after that browser starts rendering of your page by requesting other resources like CSS/JS/images etc.
  3. Page Load time : This is the total time taken by your browser to completely load a page.

So, to ensure that your site is performing as per web standards, check following values for your website (Just a note : these values are standard values, it might not fit in to your environment. so, do understand your environment  before you start investigating performance issues):

  • TTFB should be <= 100 Milliseconds; Because if it is high then your users will see a white browser page, and nothing will get loaded until and unless it receives first HTML data from server.
  • Response Time should be <= 2 seconds
  • Start Render Time should be <= 2 seconds
  • Page Load time should be between 2-3 seconds

Now, you must be curious to know, how we can check these values? Going at each layer, and checking logs at each level or there is a smart way? Luckily, there is a smart way available for you! We will have a look at it in “How” section soon!
Good to read:
http://www.webperformancetoday.com/2012/02/13/non-geeky-guide-to-performance-measurement/
http://www.webperformancetoday.com/2010/06/15/everything-you-wanted-to-know-about-web-performance/

Why Website Performance matters?

http://www.strangeloopnetworks.com/resources/infographics/web-performance-and-user-expectations/poster-visualizing-web-performance/
http://www.webperformancetoday.com/2012/03/21/neuroscience-page-speed-web-performance/
Above articles nicely explained everything!
In summary, just take a case, that if you got 20 Million visitors per month, and if your website is slow by just 1 second, then 20*1= 20 M seconds gets wasted, which they can spend somewhere else — with their family, friends or If you are running e-commerce, website then they might place multiple orders because of your faster running website! 🙂
And as per research, in this impatient era, where everyone wants everything to be done instantly  [5G!], If your site is running slow, then people will not complaint you about it. But they will go to your competitor.

How to Improve Website Performance?

Now, how to measure, these values, there are smart tools available, which you can use to know your website’s performance values, we will categorize it in two categories, Server-Side and Client-Side:
Performance problem can be divided mainly in two categories:

  1. Serve-Side : If your server is not serving requests faster, then your website is suffering from server-side/back-end performance issues. Server-Side performance issues, are really very tough to find. Because in most of the cases, you will not have a specific scenario to reproduce, You will not have Visual Studio on live server, where you can debug your code! :-). But thanks to APM tools, Performance counters, Log4Net, DebugDiag and WinDbg – these are the tools who will help you to fix your back-end issues!
  2. Client-Side : If your website is not using minify/merge than it falls in client-side/front-end performance issues, Because server has sent response rapidly. But client [Browser] is taking time to render a page, and it happens if you are not following performance best practices while building your website. It is also known as “Front-End” time. And as per stats. “80-90% time goes in front-end!”. So, If you’ve faster servers, But if your front-end is not following performance rules, then your site will never get loaded faster!

Server-Side performance testing tools:

  1. APM  Tools– APM stands for Application performance management, there is lot of APM tools available in market. You need to install their lightweight agent on your server, that’s it! It will report you everything via a nice web-based dashboard! But Dax’s favorite is, and tried one is New Relic [It’s costly. But worth! — Indeed “A web & mobile Developer’s Best Friend”]:  http://newrelic.com/
  2. Profiling – You can run profiling tool on your website, mostly in local, this tool will help you to find performance issues. It mostly helps when you’ve specific scenario to reproduce. For unknown scenarios it doesn’t help much, again Dax’s favorite is ANTS Performance Profiler from Rad Gate — http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/
  3. Performance Counters – “Performance counters is your computers Google” Nice quote from Performance webinar, Just add performance counters [Which one to add, how to analyze that something we will see in upcoming posts]
  4. DebugDiag and WinDbg — Using performance counter, If you found that there is a memory leak in your application or when Request Queuing goes high your application goes slow. And now, you would like to see what is there in heap when such thing happens — then DebugDiag and WinDbg are your friends! — http://blogs.msdn.com/b/tess/archive/2008/02/04/net-debugging-demos-information-and-setup-instructions.aspx

Have Dax missed anything? Just feel free to comment!
Client-Side performance testing tools:

  1. WebPageTest.Org —  www.webpagetest.org
  2. Pingdom Toolshttp://tools.pingdom.com/
  3. Google PageSpeed Toolshttps://developers.google.com/speed/pagespeed/
  4. Browser based tools — YSlow, HttpWatch, Firebug

Have Dax missed anything? Just feel free to comment!
Good to read:
http://yslow.org/user-guide/
http://www.webperformancetoday.com/2010/07/09/waterfalls-101/
http://www.stevesouders.com/blog/2012/10/09/webperfdays-performance-tools/
http://blog.newrelic.com/2012/09/04/improving-site-performance-with-yslow/
Still this point of time, we’ve seen how to delve in to performance issues more and find out, where you need to focus on server-side or client-side or BOTH.
Now, let’s have a look at “How” to solve them

  1. Client-side/Front-End site performance issues are relatively easy to find and fix! Just use any tool, follow the given rules, re-test and you are done!
  2. Server-side/back-end performance issues are relatively complex to find out, and once you found it fixing them might be easy! But finding back-end issue involves following level of understanding:
    1. Basics of ASP.NET — You must be saying this guy is crazy, come on, we are ASP.NET Professional and we’ve lot of years of experience, how ASP.NET works, we’ve developed and deployed lot of websites, And you are asking us to learn ASP.NET Basics? I agree with your thoughts, and I know you guys are experts in this field. But ASP.NET is a big topic, and when we develop something we work on more abstract layer, just drag and drop control. add some code behind stuff and we are done! But to work on performance stuff, you need to know lot of ASP.Net Internals, Like How ASP.NET spawns worker threads? What is HttpApplication? What is HttpModule? What is co-relation between them? When HttpApplication instance gets created? How many requests your ASP.NET application can handle? What is Request Queuing? What is Request Queued? What is Contention? You know Thread agility issue? Lot of questions correct, bouncer? Don’t worry Dax also had same questions. But after investing sometime he learnt it, and he will share those learnings with you in upcoming posts!
    2. Basics of Performance counters – Counters are your best friends! Just do learn some basics of performance counter, introduce yourself to them and vice-versa! These guys will tell you lot of secrets! (So, as your best friend!)
    3. Basics of IIS Tools : IIS got plenty of nice tools, like FRT [Failed Request Tracing] which will help you to see what is going on?
    4. Basics of Performance Testing Tools : Before fixing anything on live server, do measure it locally, and you will need performance testing tools like JMeter,WCAT,ACT,AB.exe etc. Keep them handy!
    5. Basics of APM : As discussed earlier, good to have APM tool in your armory!
    6. Basic of Dump analysis : When no one helps you, and disappoints you. Dump is a light of hope, and it won’t disappoint you for sure!

Will expand these topics in upcoming posts! So, just keep visiting, Keep reading, And if you’ve good explanation of any topic listed here, do share with us! So, as Dax! 🙂

Good to read links:

http://www.webperformancetoday.com/2013/01/31/web-performance-101-developers/
http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/entrypage/avoid-find-fix-asp-problems
http://www.softdevtube.com/2013/01/15/ten-web-performance-tuning-tricks-in-60-minutes/
http://stackoverflow.com/questions/4310719/asp-net-processmodel-configuration
http://www.guidanceshare.com/wiki/ASP.NET_2.0_Performance_Guidelines_-_Threading
http://www.aspnet101.com/2010/03/50-tips-to-boost-asp-net-performance-part-i/
Now, Dax and Gabe are really happy and they are enjoying their time! I’m sure they will keep sharing such things with us!
Have a happy faster running websites! 🙂

JQuery, JSON with ASP.NET notes

Challenge:

Before couple of weeks back, was trying to implement Facebook like live updates in ASP.NET and JSON and while doing that, faced couple of challenges. Which I thought you may find interesting!
Would like to share challenges/tasks with you. So, you can also get benefited by it when you face them!

Solution:

  • Convert Generic List to JSON : Had a generic list, which comes from DB, and needs to pass it on to UI layer, in a JSON format, used System.Web.Script.Serialization.JavaScriptSerializer class for this [using System.Web.Script.Serialization]:

[sourcecode language=”csharp”]
// ……….
List<UserUpdate> userUpdates = new List();
while (sqlDataReader.Read())
{
UserUpdate userUpdate = new UserUpdate();
userUpdate.UserID = Convert.ToInt32(sqlDataReader["ID"]);
userUpdate.UpdateMessage = Convert.ToString(sqlDataReader["UpdateMessage"]);
userUpdates.Add(userUpdate);
}
JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
string JSONString = javascriptSerializer.Serialize(userUpdates);
return JSONString;
[/sourcecode]
Just a note : If you are doing Response.Write then please do change your page’s content-type to JSON — Response.ContentType = “application/json; charset=utf-8”;

  • After every 2 second update right side data using AJAX and JSON : There will be a sidebar sitting in right side of a page and after every X seconds, it should get updated with latest updates from application:

To do this, added one UL tag on page, which will hold all data:
<ul id=”user-updates”>
</ul>
Added JavaScript on page, which checks for update every 2 second and prep ends to UL tag:
[sourcecode language=”javascript”]
<script type="text/javascript">
var url = "UserUpdates.aspx"; //This page returns JSON
var userID;
$(document).ready(function() {
// Initially all data
$.getJSON(url, function(result) {
$.each(result, function(i, field) {
userID = field.UserID;
$("
<ul>
<li><i class=’icon-text-width’>" + field.UpdateMessage + "</li>
</ul>
")
.hide().prependTo(‘#user-updates’).slideDown("slow");
});
});
setInterval(function() {
$.getJSON(url, { UID: userID }, function(result) {
$.each(result, function(i, field) {
userID = field.UserID;
$("<li><i class=’icon-text-width’></i><span>" + field.UpdateMessage + "</span> </li>")
.hide().prependTo(‘#user-updates’).slideDown("slow");
});
});
}, 2000);
});
[/sourcecode]

  • JQUERY Prepending an LI to an UL with Animation — When any new LI gets added to UL, it should come as an Animation – and invested, lot of time to achieve this requirement and finally, following link worked! [Thanks!]

http://stackoverflow.com/questions/2883154/jquery-prepending-an-li-to-an-ul-with-animation

  • Rather than showing DateTime wanted to say “Two days ago/2 seconds ago” etc. message : – Following threads helped to do so! [Thanks!]

C# solution : http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time
JavaScript based solution : http://www.aspdotnet-suresh.com/2012/02/jquery-display-time-in-facebook-twitter.html
Simple, yet powerful? Learnt a lot!
I would suggest all of you, to take a simple project for fun and try to implement it, Trust me, It will be full of fun! And you will learn a lot, and most IMP. these learnings will not go away from you for a long time. Because you learnt it with fun! Have you forgotten how to play Cricket? How to Ride a bicycle etc.? Because you learnt it funny way not in a pressurized way! 🙂
Also, If possible do blog your learnings!
Happy Coding! 🙂