Asp.net best practices

10,492 views

Published on

1 Comment
2 Likes
Statistics
Notes
  • IT Pathshala, Noida-Sector-63, offers Guaranteed JOB with .NET Training Programs.

    PAY US ONLY IF YOU GET A JOB!

    CALL US - +91-9871350999 or +91-8800394970

    Technology Centre Address: H-110, Sector-63, Noida (UP)

    Program Takeaways:

    - GUARANTEED JOB in your technology domain
    - Live Major Project development
    - Experience Letter on Training Completion
    - Certification on Training Completion
    - Project Source Code available in CD

    Program Highlights:

    - 100% Guaranteed Job – Don’t pay us if you don’t get a JOB!
    - Industry Ready Courses
    - LIVE International Project Experience
    - Exposure to corporate culture at our IT services facility
    - Networking & Interaction with Industry Experts
    - Training Provided by a reputed IT Company
    - Live Project Source Code made available in CD
    - Technology certification and experience letter at program completion
    - Online Study Content

    CALL US - +91-9871350999 or +91-8800394970

    Our website: www.itpathshala.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
10,492
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
85
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Asp.net best practices

  1. 1. ASP.NET Best PracticesFor high Performance Applications Alok Kumar Pandey Director Strategic Product Development @BrainDigit IT Solution
  2. 2. Talk about1. Introduction2. Plan and research before3. String concatenation4. Avoid round trips5. Save viewstate only when needed6. Session variables7. Server.Transfer8. Server controls when appropriate and avoid creating deeply nested controls9. Choose the data viewing control appropriate for your solution10. Optimize code and exception handling11. DataReader for fast and efficient data binding12. Paging efficiently13. Explicitly Dispose or Close all the resources14. Disable tracing and debugging15. Precompile pages and disable AutoEventWireup16. Stored procedures and indexes
  3. 3. IntroductionASP.NET is very powerful technology, however it is important to understand how touse that power to build highly efficient, reliable and robust applications. In thisdiscussion we try to highlight the key tips that we can use to maximize theperformance of our ASP.NET pages. The above list can be much longer, we willdiscus the most important ones.
  4. 4. Plan and research before• Research and investigate how .NET can really benefit you.• .NET offers a variety of solutions on each level of application design and development.
  5. 5. String concatenation //using simple string concatenation string strName = string.Empty; for (int i = 0; i < 10; i++) { strName += "Name " + i; } //Using StringBuilder StringBuilder strBuilder = new StringBuilder(); List<string> objNameList = new List<string>(); objNameList = null;//Set The name list foreach (string strName in objNameList) { strBuilder.Append(strName); }
  6. 6. Avoid round trips• Implement Ajax UI whenever possible• Use Client Side Scripts. Client site validation• Use Page.ISPostBack
  7. 7. Save viewstate only when neededViewState is used primarily by Server controls to retain state only on pages thatpost data back to themselves.Situation when we do not need ViewState• Our page does not post back.• We do not handle server control events.• We repopulate controls with every page refresh.Determine the size of your ViewState• By enabling tracing for the page, you can monitor the ViewState size for each control
  8. 8. Session variables- Avoid storing too much data in session variables- Make sure your session timeout is reasonable.To disable session state for a page,- Set the EnableSessionState attribute in the @ Page directive tofalse<%@ Page EnableSessionState="false" %>To disable session state for a specific application- Use Web.config file of the application.<sessionState mode=Off/>
  9. 9. Server.TransferIf authentication and authorization check is needed duringredirection• Use Response.RedirectTo transfer to pages in other applications• Must use Response.RedirectUse Server.Transfer to transfer control to pages in the sameapplication• Helpful to show the message like exception etc.
  10. 10. Server controls when appropriate and avoid creatingdeeply nested controls• Nothing comes for free• The HTTP protocol is statelessBetter to replace a server control to html control if1. You do not need to retain state across postbacks2. The data that appears in the control is static or control displays read-only data3. You do not need programmatic access to the control on the server-sideDeeply nested hierarchies create extra processing like• Repeater, DataList, and DataGrid
  11. 11. Choose the data viewing control appropriate foryour solution• Depend on how we choose to display data in a Web page• Always compare the pros and cons of controls before we use them in our Web page
  12. 12. Optimize code and exception handling• To optimize expensive loops,• Use For instead of ForEach in performance-critical code paths.• Also do not rely on exceptions in code• Write code that avoids exceptions• Do not use exceptions to control logic• Check for null values, If it is possible for an object to be null
  13. 13. DataReader for fast and efficient data binding• Use a DataReader object if we not need to cache data• DataReader is the optimum choice for retrieving read-only data in a forward-only
  14. 14. Paging efficiently• Retrieves only the desired data from the database• Reduces back-end work on the database
  15. 15. Explicitly Dispose or Close all the resources• Cleaned up when an exception occurs, use a try/finally block• Open connection just before need• Close it as soon as done with it• Make sure to call the Dispose or the Close method of the object if provided
  16. 16. Disable tracing and debugging• Tracing and debugging are not recommended when our application is running in production.• We can disable tracing and debugging in the Machine.config and Web.configEg.<configuration> <system.web> <trace enabled="false" pageOutput="false" /> <compilation debug="false" /> </system.web></configuration>
  17. 17. Precompile pages and disable AutoEventWireup• Precompiled pages increases the performance,• Slight performance boost by leaving the event wiring to the page author instead of performing it automatically. For example, we will need to override Page.OnLoad for the page load eventinstead of using a Page_Load method
  18. 18. Stored procedures and indexes• Use compiled stored procedures instead of RAW queries,• Proper indexes,• Reduce the chance of SQL Injection
  19. 19. Thank you

×