In this article we will explore some of the best practices in ASP.NET development.
Best Practices - These are not rules, these are conventions which will be better if followed.
Before starting I would like to request the reader to share here whatever ideas and best practices he/she uses.
1. Choose pattern correctly
Choosing the correct pattern for your application development is a must.
It's not always that 3-Tier, MVC, MVP or MVVM is best; if you have a fixed small size system which is not going to be extended in the future then 1-Tier/2-Tier will be good.
I prefer at least 2-Tier.
Always make a proper planning and understanding of the system before making any decisions.
2. DataTier
Always follow some guidelines for SQL queries.
- Alias names like a,b,emp make queries unreadable and query management becomes very difficult.
- Use alias names for tables only when self join is involved, but alias has to be meaningful and proper.
Example: TblEmployee Manager or TblEmployee Developer. - If more than a single developer will work on a project then always put a description at the top of every procedure along with the creator name.
- If in a query, in a where condition if a column with a primary key/unique key is involved, there is no need to put other conditions.
Example:
Select * from TblEmployee where EmploeyeeId=@EmployeeId
and AccountId=@AccountId
3. Application Pool
Create a new application pool for your site.
4. App_Offline.htm file
Many people are unaware of this file. When you add a htm file name such as app_offline, every ASP.NET request will be redirected to this page.
Use this page when you want to take your website offline temporarily, instead of writing your own logic for it.
5. Validation
Use ASP.NET validation controls for validation because it supports both client side and server side validation.
6. Page.IsValid
Always check for this property value in Control events like Button_click when validation is being done using Validation Controls because it's easy to bypass JavaScript code.
7. ControlState
While developing user controls if maintaining state is a must then use control states instead of viewstate.
8. Naming Convention
Always follow a consistent Naming Guidelines and standards, which should include everything, from how to declare a variable to what the structure of a stored procedure will be.
9. Foreach loop
Using a foreach loop instead of a "for" loop makes the code less cluttered.
Use a "for" loop only when an index is required.
10. Reference Type as Return Types
Try to understand the exact difference and usage of value and reference types.
Take a look at the following examples:
Public int UpdateSalary(int Salary)
{
return Salary+1000;
}
.
.
.

Chelluri NishikantPosted Feb 5, 2017, 5:27 AM
Sir how to get a job in ASP.net as a entry level