ASP.NET Advanced Tutorial

zhaozj2021-02-08  292

When the alpha version, MS called it ASP , and later came out, it was called ASP.NET, what is it? This is not just a simple question, but what is the problem it is. What is ASP.NET is, I am afraid you have seen a lot of such articles, and have your own understanding, but I am afraid that most people's understanding is not so correct. Ask a simple question, what is the relationship between ASP.NET and ASP? I am afraid the view of Chinaasp .NET version of the moderator represents most people's understanding: ASP is more than ASP :), really like this? Let us look at the following example, this code is the submission button of my own ASP.NET BBS user registration module, and the function is to store the data submitted into the database. / / Submit button Click Public Void OnSubmit (Object Sender, Eventargs E) {if (page.isvalid) {// Database Try {bbsuser myuser = new bbsuser (); if (! Myuser.getuser (txtusername.text)) {myUser.CreateUser (BBSUser.CreateType.Create, txtUserName.Text, txtPassword.Text, txtEmail.Text, txtHomepage.Text, "");}} catch (exception exp) {#if DEBUG Response.Write ( "abnormal: " Exp.Message); Return; # endif // debug server.transfer (" error.aspx ");}}} how to distinguish between ASP you used to use? You can not see the data store in the code, and all encapsulate to the CreateUser method of the BBSUser class, maybe you will say ASP, do you have a function or process? Yes, it is true that ASP.NET can also do it directly into a process and then call it, but if so, it is really only more than ASP. Let us start from the head. The biggest difference between ASP.NET and ASP is the conversion of programming thinking, not just the enhancement of functionality. ASP uses the scripting language such as VBS / JS to program, and those scripting languages ​​belong to weak types, structural programming languages, rather than domain, which significantly produces the following issues: 1. Code logic confusion, difficult to manage Since the ASP is a script language mixed HTML programming, you can't see the logical relationship of the code, and as the complexity of the program increases, it is difficult to manage the code, and even exceed the management capabilities that the programmer can achieve, Error or like this. 2, the reusability of the code: due to the structure-oriented programming method, and mixed HTML, it is possible to modify a point, and the entire program needs to be modified, and the code is reused. 3, the weak type causes potential error: Although the programming language of weak data types uses back to convenient, it is far from being lost relative to what it caused.

The above is the weakness of the language itself. There is also a problem in the functional ASP. The first is that the function is too weak. Some underlying operations can only be completed by components. At this point, it is far more than PHP / JSP, followed by lack of improvement. The error correction / debug function, this ASP / PHP / JSP is similar to this. So, what improvements are ASP.NET? ASP.NET is getting rid of the shortcomings of previous ASPs using scripting languages. It can use any programming languages ​​including C , VB, JS, etc., of course, the most appropriate programming language or MS is a C # (read) Csharp), it can be seen as a mixture of VC and Java, although MS yourself speaks more like VC in the C # core, but in fact, I still think that it is more like it and Java. First it is an object-oriented programming language, not a script, so it has all characteristics of object-oriented programming languages, such as encapsulation, inheritance, polymorphism, etc., which solves the ASPs just mentioned. weakness. The encapsulation makes the code logic clear, easy to manage, and apply to the ASP.NET to separate the business logic and HTML pages, so regardless of how the page prototype changes, business logic code does not have to do any changes; inheritance and polymorphism The reusability of the code is greatly improved, you can maximize your previous investment by inheriting existing objects. And C # and C , Java provide a complete debug / error correction system. Ok, one breath has said such a one of the theoretical things, it is better to specifically explain it in conjunction with an example in the future, I will specifically describe the development of ASP.NET in conjunction with an example of a forum. Yes, you must explain that this tutorial is not an ASP.NET entry tutorial. I assume that you have a certain understanding of ASP.NET, C # and object-oriented programming. If this is not the case, please read the article or tutorial first. The biggest difference between ASP.NET and ASP is the conversion of programming thinking, then let's take a look at how to convert programming ideas. The previous Web programming process from CGI (Perl) to ASP, PHP, and JSP programming process: the artist gives the page prototype, the programmer is filled with the page, and finally, the next time if the prototype changes, then Modify the program so that the business logic is mixed with the HTML page, it can be said that it is half a time. So, now there is ASP.NET, what should we do? Let us find an actual example, take the forum, first look at its business logic from top to bottom.

We can regard a forum to make an object, it has its own properties and methods, the common attributes have name, number of posts, number of users, etc., such, we can construct the forum object: Namespace MyownClass {Using system.data.sql; using system.data; // // Class name: bbs // // Description: Forum, construct a forum object // // Date: 2000/02/03 /// /// public class bbs {// Private variable private string m_strtitle; // bbs Name private int m_intforumcount; // Lombard Private INT m_INTTTOPICCOUNT; // Post number private int m_intuserCount; // Registered User number // Property Public String Title {get {return}} public int forumcount {get {return m_intforumcount;}} public int topiccount {get {return m_inttopiccount;}} public int usrcount} {Return m_intUserCount;}} // Constructors public BBS (string a_strTitle) {// // TODO: Add Constructor Logic here // m_strTitle = a_strTitle; // read the database MyConnection myConn = new MyConnection (); SQLCommand myCommand = new SQLCommand (); myCommand.ActiveConnection = myConn; myCommand.CommandText = "up_GetBBSInfo"; // call the stored procedure myCommand.CommandType = CommandType.StoredProcedure; try {myConn.Open (); SQLDataReader myReader;

myCommand.Execute (out myReader); if (myReader.Read ()) {m_intForumCount = (int) myReader < "ForumCount">; m_intTopicCount = (int) myReader < "TopicCount">; m_intUserCount = (int) myReader < "UserCount "} Else {throw (New Exception"))));} // Qingfang MyReader.close (); MyConn.close ();} catch (sqlexception e) {throw (New Exception) "Database error:" E.MESSAGE));}}}} This BBS class is simple, there are four private variables, corresponding to four read-only properties, the method has only one constructor with parameters, the role is to read from the database Take the corresponding data and populate four private variables.

Class construction, let us see how to use, in the page file (.aspx) that needs to display the forum (.aspx), construct four label, like this:

Registered users:
post total number:
layout: then use in the corresponding C # file: protected void Page_init (Object Sender Eventargs e) {/// codegen: this call is required by the ASP Windows form designer. // initializecomponent (); // Initialization page object // Create BBS object try {m_objbbs = new bbs ("Eagle Village Forum");} Catch (Exception Exp) {#if debug response.write ("Initializing BBS object error:" Expurn; # endif // debug server.transfer ("error.aspx");

转载请注明原文地址:https://www.9cbs.com/read-3475.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.053, SQL: 9