One of ASP. NET 4.0's new feature series starts with page tagging

Source: Internet
Author: User

Vs2010 was officially released in May April. ASP. NET 4.0 has brought me some new things. Try it.

 

1. Start with the page tag <%>
2. in ASP. NET 4.0, you can use a custom provider for outputcache.
3. Enhanced Seo support for metakeywords, metadegion, and redirectpermanant
4. Seo-enhanced URL Routing
5. Output more pure HTML code, viewstatemode, clientidmode, checkboxlist, etc.

In ASP. in net4.0, <% Symbol Expression %> has four forms: <% = "Hello World" %>, <% $ expression %>, <% # expression %>, <%: ABC %> let's take a look at it separately.

1. <% = expression %> This method supports ASP, JSP, and so on. It directly outputs the value of the expression, which is equivalent

 
Response. Write (expression );

2. <% $ declarationexp: expression %> This is a declarative expression in ASP. NET 2.0 was introduced. We can use this expression to output the configuration in appsettings, set the connection string for the sqldatasource control, and so on. net 4.0, We can output the parameter values in URL routing in this expression, or get the URL after urlrouting according to the settings.
For example:
1) display the current action value of URL routing in literal.

<Asp: literal id = "L" enableviewstate = "false" text = "<% $ routevalue: Action %>" runat = "server"> </ASP: literal>

2) input parameters to display the URL after Routing

 
<Asp: Label id = "LB" enableviewstate = "false" text = "<% $ routeurl: controller = category, Action = edit, id = 1%> "runat =" server "> </ASP: Label>

In. net 4.0 supports the following default supported expressions: resources, connectionstrings, etettings, routeurl, and routevalue in the root configuration file web. config system. configuration in the Web/compilation/expressionbuilders configuration section

For more information, see http://msdn.microsoft.com/en-us/library/d5bd1tad (V = vs.100). aspx
Http://msdn.microsoft.com/en-us/library/system.web.compilation.routeurlexpressionbuilder.aspx

3. <% # expression %> indicates data binding. Only the databind method can be called to output the bound value. It is usually used in template controls such as DataGrid, repeater, and listview.

4. <%: expression %> it is a new expression that outputs the expression after htmlencode. If the expression type is ihtmlstring, it uses the tohtmlstring () of the ihtmlstring interface () urlencode ,. in net 4.0, The htmlstring class implements this interface to avoid repeated htmlencode.

For example:
1. Use an expression when htmlencode is required

 
<%: "<H1> I 'a test  

Output

 
<H1> I 'a test  

2. Use expressions when htmlencode is not required

 
<%: New htmlstring (" 

Output

 
<H1> I 'a test  

This cool feature is widely used in ASP. net mvc 2.0.

These expressions appear on the ASPX page and are compiled when the ASPX page is compiled.ProgramThe regular expression is used to parse these expressions into the background.CodeTo execute

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.