Summary of study asp.net of Frog Frog (one)

Source: Internet
Author: User
Tags copy versions client visual studio
ASP.net has known Microsoft's asp.net for a while, and feels that ASP.net does have a significant improvement in functionality and performance over ASP (I've been writing an ASP program) and summed up some of the content here to share with you. Because I have little experience, so there are technical errors in the article or need to improve the place, welcome to communicate with me.

As individuals prefer to use the C # language, so most examples are examples of C #, but here is mainly to explain some of the original rational things, so there is not too much reliance on specific language, if you are more inclined to VB can refer to the following article to temporarily change their thinking:

Code Skin--c# and VB

Http://blog.csdn.net/onlytiancai/archive/2004/07/16/43137.aspx

VB.net and C # syntax comparisons

Http://blog.csdn.net/onlytiancai/archive/2004/07/16/43134.aspx



I would like to talk about my experience from the following aspects, mainly to write about the security and performance considerations in some of the choice issues

1.web user control, Web custom control, background encoding class,. NET component usage:

2. Caching (cache and application) use of the occasion:

3.web use of service and component classes:

Use of 4.vb.net and C #:

Use of 5.DataReader and dataset:

6. Use of database and XML data:

7. The use of string connectors and StringBuilder.

8. Windows based and form-based authentication usage scenarios.

9. Use of static methods and Non-static methods.

The use of 10.HTML controls and server controls.

11. Client-side technology and service-end technology use occasion.

12.DTD and Schema use scenarios

13. The use of string-handling functions and regular expressions.

14.web Service synchronization Bar and the use of different calls

15. Instantiation class and inheritance class use occasion

16. The use of single value binding and multivalued binding



1. Web user controls, Web custom controls (custom server controls), background encoding classes,. NET components (assemblies) for use:

These techniques are used to reuse code, but the use of the occasion is different, I will try to explain the differences between them and the relationship between.

Let's take a look at the characteristics of Web user controls and Web custom controls:





Web User Control
Web Custom Controls

Web user controls are easy to create,
Web custom controls are difficult to create,

Limited support available only to users who use visual design tools
Provides complete visual design tool support for consumers

A separate copy of the control is required in each application
Only a single copy of a control is required in the global Assembly cache

Cannot add to the Toolbox in Visual Studio
Toolbox that you can add to Visual Studio

Apply to Static layout
, suitable for dynamic layout.






As you can see, Web user controls apply to:

1. Reusable elements on the page, such as title, product catalog, menu, register control, etc.

2. Using the caching function of the user control, the pages that are often browsed by the cache can improve the performance of the page.

3. Encapsulate repetitive page elements into user controls, reducing the amount of code on each page

However, if you want to create a more extensive reusable control than your own application, you need to consider using a Web custom control.

If you have MSDN installed, refer to the links below for suggestions about using Web user controls and Web custom controls.

Ms-help://ms. Vscc.2003/ms. Msdnqtr.2003feb.2052/vbcon/html/vbconwebusercontrolsvscustomwebcontrols.htm

Give an example of how to create a user control:


Hello, I'm frog Frog.

Save the above code as WAWAUC.ASCX, and the user control is built. (You need to specify this address when invoking the user control)

The following example shows how to cache a user control. After you write the control, you can implement the control's cache (fragmentation cache) by adding the following sentence to the top of the. ascx file.


Users often visit but infrequently updated data into user control and cache, and some real-time information do not cache, so you can improve the overall performance of the page, and not allow some real-time information can not be updated in time.

Briefly explain some of the parameters of OutputCache, which are available in. aspx and. ascx

OutputCache: Use caching.

Duration: Specifies the time, in seconds, of cache content

Location: When set to server use caching only on servers, network agents in the middle can cache copies of pages when set to downstream, set to client to indicate that browsers can cache pages, set to any to indicate that these caches can be used

VaryByControl: Allows caching of controls on the page, which are used on the. aspx page.

VaryByParam: Depending on the post pass parameter to form a different version of the cache, want to cache the entire page at any time can set the value to none, if you want all the parameters to use different versions of the cache can set the parameter to *.

VaryByCustom: Depending on the different versions of the browser to form a different version of the cache, or with the specified string to form a different version of the cache, set to browser can be used for different versions of browsers to use different versions of the cache, which is useful for displaying data on different browsers or devices.

VaryByHeader: A different cache is formed based on different HTTP headers.

Custom server controls can reuse code between different applications, you can create custom controls from scratch with HTML, or you can create custom controls on existing server controls (generally referred to as compositing controls). Give an example of how to create a custom server control:

Using System;

Using System.Web.UI;



Namespace Wawacontrols

{

public class Hellocontrol:control

{

protected override void Render (HtmlTextWriter writer)

{

Writer. Write ("

Hello, Frog frog
”);

}

}

}

As you can see, custom user controls inherit from System.Web.UI. control, and rewrite the Render method of the control class to change the default output of the controls class, and then use the HtmlTextWriter to output arbitrary HTML code and script code, so that any complex custom controls have been made.

Save the above code as MyCustomControl.cs

After writing the code, you need to compile it into a. dll file, complete with the CSC command tool with the. NET Framework, and first write a batch file, as follows:

Set Assemblies=system.dll,system.web.dll

Csc/t:library/out:mycustomcontrol.dll mycustomcontrol.cs/r:%assemblies%

Pause

Briefly describe the use parameters of the CSC command:

/T represents the output type, which uses the library to indicate the output as a. dll file, in addition to an EXE (console program), Winexe (Windwos program), and so on,/out indicates the file name you want to output, followed by the name of the file you want to compile. R means that you need to compile those files into the file to be generated, where the set command first defines the System.dll,system.web.dll as a variable and uses it directly, and then pauses the output with a pause command. Note that set and pause are the system's console (CMD) commands, which originate from the old DOS. Save the above code as a. bat batch file, the two-machine run can generate the. dll file, and finally put the file in the Bin directory for standby.

There are some differences when working with user controls and custom controls.

The user control invocation example is as follows: first enter the following code when you need to invoke the beginning of the control.


It is then invoked in the appropriate place with code similar to the following:


Note that the above code is placed in the server Control form container.

Brief description of each of the Register's parameters.

TagPrefix: The collection name of the control group, which is the part of the call control that precedes the colon

TagName: The name of the control, which is the part of the calling control that follows the colon

SRC: The source file address of the control

Namespace: control's named control (for server controls)

Assembly: Control collection (user server control)

The example of a custom control invocation is as follows: first enter the following code when you need to invoke the beginning of the control.


It is then invoked in the appropriate place with code similar to the following:


For a detailed method of creating a user control, refer to the following address:

Ms-help://ms



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.