Mistakes that are easy to make in asp.net

Source: Internet
Author: User
Tags config file upload dreamweaver root directory visual studio
Asp.net| Error

Today in the forum wandering, see a friend asked ASP. NET programming should pay attention to what problems, there are friends to answer, wrote the 21 big points of the voluminous. Personally think that these rules should be based on the actual situation of the project, to promote dialectical materialism.
Carefully looked at also found themselves in the project development process is really such a problem, these problems are also a legacy of the ASP process, to give their own habit of a good change.

1. Use server side include to introduce a common page composition to aspx.
Under the asp.net mechanism, you should use ASCX (Web user control) to implement it. Ascx provides more controllable interfaces. And more importantly, Ascx is a class. A real class. It can be fully controlled.

2. Do not use Web.config
Web.config provides a very rich configuration management interface. Is the core part of an application. But many people's web.config are often empty. Or have never been modified.

Web.config is primarily reserved for server configuration and global information, which is greatly reflected in the forums code of the Telligent Systems:
1. Introducing namespace Information
2. Data access, File upload directory, resource file directory and other global information

3. Use Response.Write to output messages to the front end
Asp. NET platform of response and ASP response is very different. Although it represents the same meaning, it is already very different in usage. The Response.Write content is output only to the front end of the page. The correct way to output messages to the front end is to use placeholder.
~~~~~~~~~~~
This is no skill, and people who are familiar with HTML should know how to do it.


4. Manage user connection status using a series of sessions
This approach is misused in the ASP. In a asp.net environment, the right thing to do is to design a class. Save the data in a structured way. Encapsulates access to session or cookie.
~~~~~~~~~~~~~~
It's supposed to be about saving the user's object.

5. Use Session to verify identity
It's almost a common problem. Asp. NET provides a set of APIs for user authentication. Type is forms validation or Windows authentication. This quick start has a very clear section to explain. Most people can still rely on assigning a value to the session to maintain the user authentication status.

~~~~~~~~~~~~~~
Many people do use this, they have such a problem, should be changed

6. Use the Response.Redirect redirect page
This can be used when necessary. But not abused. The misuse of redirects has proved to be a logical cause of serious confusion. This is the practice of using the page as the program unit. Using the front controller mode will bring the user's operational logic together]

~~~~~~~~~~~~~
Response.Redirect just page jump has turned

7. Use too many ASPX pages
In ASP environment, the program unit is only *.asp page, ASP. NET is not like this, there are back-end class library, ascx and so on. You should focus your business logic on separate units instead of using an ASPX for an operation. More often, ASPX manages page logic as a container for ascx or custom control. While ASPX reuses ascx, ASPX is also reused as a unified page composition.

8. Copy code between multiple logical units and modify the corresponding logic
Reuse. Reuse. Reuse. The principle of dealing with such problems is that no process of the same or similar kind occurs. If you use the above method, the result will be catastrophic once there is a major logical change.
~~~~~~~~~~~~~~~~~~~
Increase code reusability, you should less "copy" code

9. Fear of using a dataset.
Many people were terrified by the dataset. Think "affirmative" affects performance. But not even the first attempt. They always think that their products must be important and that they should be "cautious" in design. They often use ArrayList or design low-level classes to save collection data. Hard data is poured into the work.
~~~~~~~~~~~~~~~~~~~~~~~
Your own set of classes also has its own advantages, if the data collection is not connected, then directly with the DataTable.

10. Pay too much attention to "performance".
The mechanism of ASP.net viewstate is particularly dissatisfied. or always try to persecute others. Instead of making himself very tired. It may be more civilized to pay more attention to a few databases while dealing with ViewState.

~~~~~~~~~~~~~~~
If you are developing a system that uses fewer people, performance considerations are not primary, because the average server can serve a larger number of people, and if performance can become a system bottleneck, it should be greatly optimized, less server control

11. The application root directory is messy.
Asp. NET is a development project. Not a Web site. Different resources should be placed in categories. For example, all static resources (style sheets, scripts, images) are organized together. You can even write a set of APIs to manage them. ASPX should be put together. Ascx should be put together. . What about *.cs? You should put them in another project.
~~~~~~~~~~~~~
This agrees that at least the data access layer is to be a separate class library.

12. The process of writing access to the database
The work should be handed over to dataaccess application block. You have to switch connection, why bother.

13. What you write is most reliable.
The opposite is often true. Pay more attention to the use of products written by others. And don't charge you money, why so face-saving?

14. Randomly naming aspx file names
This is the most painful. The ASPX file name is not only easy to identify. You should also follow certain rules. Because behind each aspx has a class with the same name, imagine how hard it would be. In addition, most people do not know the name space for managing their own projects. It's like seeing a ledger.

15. Never be inherited or derived
Some classes that have the same behavior should derive from the common base class. In practical sense, our aspx should have a base class pagebase. Because there are always some common features that need to be abstracted out.

16.0 Property
Their class (the ASPX corresponds to) is only private method. Do not disclose any of their secrets. This must be the survival of Java.

17.0 ascx
Needless to say, he hasn't learned to asp.net.

18. Use Dreamweaver to "draw" ASPX
This group of people are artists. There are even people who are very intoxicated to discuss how to better "consolidate" Dreamweaver and visual Studio.

19. Only familiar with System.Web.UI.WebControl and System.Data.SqlClient there should be some familiar class libraries.

20.0 Notes
These are very clear in the heart of the quick. The default annotation generated by one IDE is horizontal there regardless.

21.0 Events
Ignorant of "event-driven". Only know to write the process in Page_Load (). or double-click a button to write the Xxx_clock () process. Event and delegate are not seen in their programs.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.