Skip to content
November 1, 2014 / kiranpatils

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! :-)

August 10, 2014 / kiranpatils

You are starting your career in IT Industry? Here are my learnings for you!

Hello Folks, Sorry I am facing challenges in keeping this blog updated. I wish can get more than 24 hours :-). I know it’s not possible. But will keep posting on this blog. Because from this blog only I got to learn lot of things. While sharing things with you. Quantity will be less compared to earlier. But quality will be same/more than earlier for sure! Because I believe in never compromising with quality!

Start-CareerMonth of May-July is the month, when every company starts on-boarding university/college pass-outs in their company. So, lot of new people start working professionally in IT Industry. So, if you are one of them — I welcome you to an IT Industry!

Now, when you start working in this Industry, You feel lot excited. But more confused as well. Because what you learnt in college, and what people do in industry is totally different, until and unless you are from Good College/University. Who encourage to have working professional as a guest lecturer.

When you start working for any company. And you got a nice mentor — Who can clear all your doubts, Help you understand what is right, what is wrong, Guide you in getting comfortable with all the tools and terminologies, Who is always there for you. But if you get one then you are lucky!

As per my view good mentor should have :

  1. Lot of patience
  2. And passion about the profession what they are in

When I started my career, I’ve been lucky at times, by having great mentors, who taught me What To Do, And How To DO. And have been super lucky to have some not so good mentors, from whom I Learnt — What Not To Do, How Not To Do, And How Not To Behave. And my big thanks to second one. Because I learnt a lot from them then the first one!

Since few year, I’ve been lucky enough to mentor — super talented and smart people. And I’ve thoroughly enjoyed them shining. Because they were Diamonds. I just got a chance to polish them and make them shine! You are also a Mentor? Then buddy you got a big responsibility on your shoulders. Because I believe Mentor has to play a role, Which Parents played during nurturing, Teacher played during School/College. So, when your mentee comes to you with small questions — Don’t lose patience, answer them politely.  Quench their thirst. And while doing so, you will learn a lot of new things — It’s a two-way process. I learnt a lot from my students. Basically if we just look around, We’ve a lot to learn from each others! — John West Sitecore CTO nicely said on Mentoring:

When a new developer joins your team or project, be friendly and let them know you are available for a two-way learning process. If an inexperienced Sitecore developer has a newbie question, instead of ignoring it or feeling frustrated, show that you care, take pride in trying to educate them on the topic, and try to provide pointers to the next few areas they could research. This works best when we all approach it the same way. Consider everyone with whom you interact to be both your mentor and your mentee. When I used to teach CMS training, I was surprised constantly by how much I learned from my students. In fact, I think each of us has something to learn from every other individual.

Source : http://www.sitecore.net/belgie/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/06/My-Sitecore-Story-Mentoring.aspx

You may also like these:

While mentoring them, What I used to do, used to go back in my career and check, What Good things I learnt? — So, I can pass on to them. What Bad Things I learnt? — So, I can’t pass same to them. What I haven’t got? — So, I can get it for them.

So, each year – I meet a lot of young people joining our industry, and I make sure I share my learnings with them and help them shine! At one evening I thought, At each year — How many young folks — I will meet — 4,5,6 That’s it! — So, Why don’t I share my learning via my blog. So, who are starting your career, can focus on it. And if someone is new in mentoring and one of my learning can help them then I feel paid off!

Disclaimer : This is based on my learnings. I am not expert on this subject. But few basics which I learnt through my journey and have noted it down. Which I am sharing with you. So, if you think something might not work for you. Feel free to ignore it

Let’s go!

  1. Learn : When you start your career, Keep focusing on Learning and NOT Earning! [As Allan Border Said to Harsha Bhogle — Take care of the runs – the dollars will take care of themselves.] An Advice I follow and give — For Initial years — Just learn as much as you can! Spend as much as time you can to learn the things, understand things. Ask questions. Do R&D
  2. Mentor : If possible find a Good Mentor and follow him/her
  3. Don’t Say No : If some new task is coming up to you. Don’t say NO — If you don’t know, tell them I will need sometime. But i will do it.  Be a Go-Getter [Quotable Quote : Richard Branson — ‘If somebody offers you an amazing opportunity but you are not sure you can do it, say yes – then learn how to do it later!’] But Yes, don’t get overburdened and over commit.
  4. Give Respect : Give respect to your seniors, subordinates and even office peons!. Be a team player! And they will love to work with you!
  5. Master your Skills : Whatever skills you are in for example .NET Developer/Java Developer/QA — Master it! And to be different from crowd — Get your self certified — I did most of my Microsoft Certifications during initial years — It not only added value. But also clarified lot of my basic thoughts about programming, I came to know lot of new API — Which made my work easier, and faster. [Yes, please read Microsoft certification books before giving exam, and DON’T GIVE EXAMS BY JUST READING DUMPS]
  6. Focus on your Coding Standards : They will consider that you care for your code!
  7. Read Read Read : In the era of internet as well, disconnecting from live world and reading a book for Minimum 30 minutes Enriches you. First read as many technical books you can may it be – OOPS, Design Patterns, .NET Frameworks, 97 Things every programmer should know or talk to your colleagues and find out which book they like more. Apart from that read the books you like Fiction/Non-Fiction/Self Help — This will keep you motivated! This is so long back I wrote on World Book Day : Did you know that, today is World Book day?!Books can be really your best friend! – Who gives a lot, and asks nothing in return!, which expands your vision about life! Who helps you to stand like a rock in difficult situation! Who makes you laugh, who makes you cry!If you read technical books – your technical knowledge will get increased and if you read other books (Biography, self-help, novel etc.) – your life’s knowledge will get increased – at last you will feel enriched for sure!It’s interesting, when I talk to people and ask about reading books they say – “Where is time to read the books?” – It’s same as driving a fast running car. But you don’t have a time to fuel it!:-)In this fast pacing era, promise yourself to daily read for min. 30 minutes, it will surely change your life – it worked for me, and I’m sure it will work for you as well!So, grab a copy of a book which you was “planing” to read from a long time and start reading it “today”!Happy World Book day!
  8. Document your learnings : In your initial days you will learn new things at every footstep. Our teacher taught us, Whatever new thing you learn document it. So, your knowledge gets organized in a proper manner, it gets stored in your permanent sector. And if you can write  your blog then nothing great like that! The one blog you are reading is the best example of it! It improved my writing Skills and when people comment on blog — “You saved my day, God Bless you!” — That’s the best feeling you can ever have — Good Reads : http://pluralsight.com/training/Courses/TableOfContents/get-involved and http://www.hanselman.com/blog/YourWordsAreWasted.aspx
  9. Communication Skills : Sharpen your written and verbal skills. Because along with compilers you’ve to work with HUMANS. And when you get stuck with something. You’ve to explain it nicely to your senior, colleague, subordinate, Or In Global era to someone else sitting in U.S/U.K Or in Forum or To Support guys. And before you start working you’ve to understand requirements as well. If you can’t deliver something as committed, please communicate before hand.
  10. Develop Tools —  When you learn something new in Technology. Think of how you can use it in your day-to-day life. If not in your project then can you build a small tool for your personal use or professional use or for your company’s use? It will give two benefits — It will clarify your concepts thoroughly, and at the end of  the day, you will have a tool which simplifies someone’s task. See Tools i wrote for fun — PolyglotSkype, TimeZoneConverter or you can start your open source project on GitHub!
  11. Stand in tough time :When something is not working and the whole team is in tough time. Go and stand their. You might not be able to help. But see what you can do. At times fresh perspective might show a way to solve a problem! And you learn more in tough situations than day-to-day situations!
  12. Share Knowledge — Learnt something new? Share with someone else as soon as you can! Don’t feel insecure while sharing the knowledge. Good Read : http://prakashiyer.com/a-tale-of-two-seas/
  13. Track your progress : Periodically, take a halt and check how you are moving? What good things you did? What bad things you did? If needed talk to your Mentor/Senior and ask for an HONEST Feedback — Don’t wait for Annual Appraisal. BTW, I’m big fan of writing Journals. Give it a try, It will give you astonishing results!
  14. Usergroup meetings : If possible go for user group meeting
  15. Focus Focus Focus : Be focused, In this era of Social Media, you have no idea, how much of your time this social media mediums can eat. I’m not against in being touch with friends and family — That matters a lot! But while you are working — You are working! And When you are playing, You are playing — Then don’t work! I believe in “Work Hard, Play Hard” And you got finite number of key strokes in your life, please don’t get it wasted — http://www.hanselman.com/blog/YourWordsAreWasted.aspx Check your keys left : http://keysleft.com/ [I have only 156,038,394 keystrokes left before I die.] and “Choose a job you love, and you will never have to work a day in your life.” – Confucius
  16. Quality : Never Never Never compromise on quality. If you’ve to delay your software delivery by a day or deliver one feature less — In place of a quality — It’s a good deal! If you’ve to burn yourself for a quality — Just do it! Steve Jobs is the prime example of quality lovers and he nicely said “When you’re a carpenter making a beautiful chest of drawers, you’re not going to use a piece of plywood on the back, even though it faces the wall and nobody will ever see it. You’ll know it’s there, so you’re going to use a beautiful piece of wood on the back. For you to sleep well at night, the aesthetic, the quality, has to be carried all the way through.” Good Read : http://blog.hubspot.com/marketing/steve-jobs-inspirational-quotes-im-slideshare
  17. Be Efficient  : Complete your assigned tasks on time. Do a Time management. Say No where you can Say NO.
  18. Be Responsible : If you take more responsibility you will be assigned on more and important projects — and you will be important player of your team!
  19. Basics : And one advice, I always give — “Always Stick  to your Basics” In whatever things Technical/Non Technical — Because it matters! “Back to Basic, Stick to basics, because a basic always works!”

Have I missed something? Feel free to comment

I hope this pointers, help you to shine in your career! Always Remember — “No idea works, Unless you do!”

“Twenty years from now you will be more disappointed by the things that you didn’t do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover.”

And If you need any help from my side, Just give me a shout!

Have a Happy and Nice Vacation! :-) [“When Passion becomes Profession, life Becomes Vacation!”]

Good Reads:

Driving Your Career : http://www.brianhprince.com/2010/04/14/driving-your-career-series-transcripts/

June 21, 2014 / kiranpatils

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:


protected void Page_Init(object sender, EventArgs e)<br clear="none" />        {        <br clear="none" />            Page.EnableEventValidation = false;<br clear="none" />        }

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! :-)

February 15, 2014 / kiranpatils

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


<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"
/>

/*
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;

}
/// <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>

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! :-)

February 15, 2014 / kiranpatils

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:

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;

}
  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

 

September 29, 2013 / kiranpatils

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! :-)

August 25, 2013 / kiranpatils

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! :-)

 

Follow

Get every new post delivered to your Inbox.

Join 390 other followers